Commit 0db9b293 authored by Kristin Wright's avatar Kristin Wright

Introduced server classes. Only tested on one-node network.

parent bb87f1dd
......@@ -18,6 +18,14 @@
<hr>
<H3>Current Release 1.0 </a> [PENDING]</h3>
<ul>
<p>
<LI><B><A HREF="http://www.cs.utah.edu/~kwright/">[kwright]</A></B>
<b>Tue Jul 18 13:15:00 MDT 2000</b><br>
Finished adding inquiry "class". The server now detects
if an inquiry is a duplicate and, if from itself, ignores it;
if from a neighbor, sends an interface list. This has not been
well-tested.
<p>
<LI><B><A HREF="http://www.cs.utah.edu/~kwright/">[kwright]</A></B>
<b>Tue Jul 18 10:55:47 MDT 2000</b><br>
......
/*$Id: discvr.h,v 1.2 2000-07-06 22:50:59 kwright Exp $*/
/*$Id: discvr.h,v 1.3 2000-07-18 19:19:27 kwright Exp $*/
#ifndef _TOPD_DISCVR_H_
#define _TOPD_DISCVR_H_
......@@ -88,7 +88,7 @@ void
get_rtaddrs(int, struct sockaddr *, struct sockaddr **);
u_int32_t
compose_reply(struct ifi_info *ifi, char *mesg, const int mesglen);
compose_reply(struct ifi_info *ifi, char *mesg, const int mesglen, int sendnbors);
#endif /* _TOPD_DISCVR_H_ */
......@@ -18,7 +18,7 @@
*
* ---------------------------
*
* $Id: packet.h,v 1.2 2000-07-13 19:04:28 kwright Exp $
* $Id: packet.h,v 1.3 2000-07-18 19:19:28 kwright Exp $
*/
#ifndef _TOPD_PACKET_H_
......@@ -50,6 +50,11 @@ typedef struct topd_inqid {
#define TOPD_INQ_SIZ ALIGN(sizeof(struct topd_inqid))
struct topd_inqnode {
struct topd_inqnode *inqn_next;
struct topd_inqid *inqn_inq;
};
/*
* Neighbor (reply) packets consist of
*
......
......@@ -18,7 +18,7 @@
*
* ---------------------------
*
* $Id: reply.c,v 1.4 2000-07-18 17:13:44 kwright Exp $
* $Id: reply.c,v 1.5 2000-07-18 19:19:28 kwright Exp $
*/
......@@ -34,7 +34,7 @@ extern topd_inqid_t inqid_current;
* one long neighbor list.
*/
u_int32_t
compose_reply(struct ifi_info *ifi, char *mesg, const int mesglen)
compose_reply(struct ifi_info *ifi, char *mesg, const int mesglen, int sendnbors)
{
struct topd_nborlist *nborl;
struct ifi_info *ifihead;
......@@ -74,6 +74,7 @@ compose_reply(struct ifi_info *ifi, char *mesg, const int mesglen)
nid += ETHADDRSIZ;
bzero(nid, ETHADDRSIZ << 1);
if ( sendnbors != 0 ) {
while ( nborl != NULL ) {
nbor = (struct topd_nbor *)nw;
nw += nborl->tdnbl_n * sizeof(struct topd_nbor);
......@@ -85,6 +86,7 @@ compose_reply(struct ifi_info *ifi, char *mesg, const int mesglen)
nborl = nborl->tdnbl_next;
}
}
}
return (nw - mesg);
}
......@@ -18,13 +18,18 @@
*
* ---------------------------
*
* $Id: serv_listen.c,v 1.4 2000-07-18 17:13:44 kwright Exp $
* $Id: serv_listen.c,v 1.5 2000-07-18 19:19:28 kwright Exp $
*/
#include "discvr.h"
#include "packet.h"
#include "util.h"
enum {DUP, DUP_NBOR, NEW};
/*
* Is this used anymore?
*/
extern topd_inqid_t inqid_current;
/*
......@@ -37,6 +42,32 @@ extern topd_inqid_t inqid_current;
*/
u_char myNodeID[ETHADDRSIZ];
/*
* Return 0 if the inquiry is not from us, 1 if it is.
*/
int
from_us(struct in_pktinfo *pktinfo, struct ifi_info *ifihead)
{
struct ifi_info *ifi;
for( ifi = ifihead; ifi != NULL; ifi = ifi->ifi_next) {
if ( bcmp(&ifi->ifi_addr->sa_data, &pktinfo->ipi_addr.s_addr,
sizeof(pktinfo->ipi_addr.s_addr)) == 0 ) {
return 1;
}
}
return 0;
}
/*
* Return 0 if the two inquiries are identical, non-zero if not.
*/
int
inqid_cmp(struct topd_inqid *tid1, struct topd_inqid *tid2)
{
return( bcmp((void *)tid1, (void*)tid2, sizeof(struct topd_inqid)));
}
void
print_ifi_info(struct ifi_info *ifihead)
{
......@@ -67,7 +98,7 @@ print_ifi_info(struct ifi_info *ifihead)
void
serv_listen(int sockfd, struct sockaddr *pcliaddr, socklen_t clilen)
{
int flags;
int flags, class;
const int on = 1;
socklen_t len;
ssize_t n;
......@@ -77,6 +108,7 @@ serv_listen(int sockfd, struct sockaddr *pcliaddr, socklen_t clilen)
struct in_addr in_zero;
struct ifi_info *ifi, *ifihead;
struct in_pktinfo pktinfo;
struct topd_inqnode *inqn, *inqhead = 0;
/*
* Use this option to specify that the receiving interface
......@@ -138,12 +170,30 @@ serv_listen(int sockfd, struct sockaddr *pcliaddr, socklen_t clilen)
* There are 3 possible classifications for this inquiry.
* Our response to the inquiry depends upon its classification:
*
* - New inquiry -> forward and reply
* - New inquiry -> forward and reply (NEW)
* - Duplicate inquiry
* - From us -> ignore
* - From another -> reply with interface list.
* - From us -> ignore (DUP)
* - From another -> reply with interface list. (DUP_NBOR)
*
* We now classify each inquiry.
*/
for ( inqn = inqhead; inqn != NULL; inqn = inqn->inqn_next ) {
if (inqid_cmp(inqn->inqn_inq, (struct topd_inqid *)mesg) == NULL) {
/* Duplicate inquiry */
if (from_us(&pktinfo, ifihead)) {
class = DUP;
} else {
class = DUP_NBOR;
}
} else {
/* New inquiry */
class = NEW;
}
}
if (class == DUP) continue;
/*
* Save the inquiry ID into inqid_current.
*/
......@@ -154,13 +204,24 @@ serv_listen(int sockfd, struct sockaddr *pcliaddr, socklen_t clilen)
*/
ifihead = get_ifi_info(AF_INET, 0);
if (class == NEW) {
struct topd_inqnode *save = inqhead;
inqhead = (struct topd_inqnode *)malloc(sizeof(struct topd_inqnode));
inqhead->inqn_inq = (struct topd_inqid *)malloc(sizeof(struct topd_inqid));
if (inqhead == NULL || inqhead->inqn_inq == NULL ) {
fprintf(stderr, "Ran out of room while expanding inquiry list.\n");
exit(1);
}
memcpy(inqhead->inqn_inq, mesg, sizeof(struct topd_inqid));
inqhead->inqn_next = save;
forward_request(ifihead, &pktinfo, mesg, n );
}
if ( (reply=(char *)malloc(BUFSIZ)) == NULL) {
fprintf(stderr, "Ran out of memory for reply mesg.\n");
exit(1);
}
n = compose_reply(ifihead, reply, BUFSIZ);
n = compose_reply(ifihead, reply, BUFSIZ, class == NEW);
fprintf(stderr, "replying: ");
print_tdreply(reply, n);
free_ifi_info(ifihead);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment