reply.c 2.88 KB
Newer Older
Kristin Wright's avatar
Kristin Wright committed
1
/* 
Mike Hibler's avatar
Mike Hibler committed
2
 * EMULAB-COPYRIGHT
Kristin Wright's avatar
Kristin Wright committed
3 4 5 6 7 8 9 10 11 12
 * Copyright (c) 2000 The University of Utah and the Flux Group.
 * All rights reserved.
 *
 * ---------------------------
 *
 * Filename: reply.c
 *   -- Author: Kristin Wright <kwright@cs.utah.edu> 
 *
 * ---------------------------
 *
Mike Hibler's avatar
Mike Hibler committed
13
 * $Id: reply.c,v 1.11 2004-06-17 18:17:01 mike Exp $
Kristin Wright's avatar
Kristin Wright committed
14 15 16 17 18
 */


#include "discvr.h"
#include "packet.h"
19
#include "util.h"
Kristin Wright's avatar
Kristin Wright committed
20 21

extern u_char myNodeID[ETHADDRSIZ];
22
//extern u_char parent_nodeIF[ETHADDRSIZ];
Kristin Wright's avatar
Kristin Wright committed
23
extern topd_inqid_t inqid_current;
24
//extern u_char receivingIF[ETHADDRSIZ];
Kristin Wright's avatar
Kristin Wright committed
25 26 27 28 29
/*
 * Concatenate all the individual interfaces' messages into
 * one long neighbor list.
 */
u_int32_t
30 31
compose_reply(struct ifi_info *ifi, char *mesg, const int mesglen, int sendnbors,
			  u_char senderIF[], u_char recverIF[]) 
Kristin Wright's avatar
Kristin Wright committed
32
{
Kristin Wright's avatar
Kristin Wright committed
33 34 35 36 37
        struct topd_nborlist *nborl;
	struct ifi_info      *ifihead;
        char                 *nw;
	char                 *nid;
	struct topd_nbor     *nbor;
Kristin Wright's avatar
Kristin Wright committed
38 39 40 41 42 43 44

	nw = (u_char *) mesg;
	
	/* Add on the INQ ID we're responding to. */
	memcpy(mesg, &inqid_current, sizeof(topd_inqid_t));
	nw += sizeof(topd_inqid_t);

45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
	nid=nw;
	nw += ETHADDRSIZ << 2;
	if ((char *)nw > mesg + mesglen ) { 
		        fprintf(stderr, "ran out of room and you didn't do anything
						reasonable.1\n");
			return 0;
		}
	memcpy(nid, myNodeID, ETHADDRSIZ);
    nid += ETHADDRSIZ;
	bzero(nid, ETHADDRSIZ);
    nid += ETHADDRSIZ;
    memcpy(nid,senderIF,ETHADDRSIZ);
    nid += ETHADDRSIZ;
    memcpy(nid,recverIF,ETHADDRSIZ);

Kristin Wright's avatar
Kristin Wright committed
60
	for (ifihead = ifi; ifi != NULL; ifi = ifi->ifi_next) {
Kristin Wright's avatar
Kristin Wright committed
61 62
	        nborl  = ifi->ifi_nbors;

Kristin Wright's avatar
Kristin Wright committed
63 64
	        /* Add check for control net -LKW */
	        if (ifi->ifi_flags & !IFF_UP || 
65
		    ifi->ifi_flags & IFF_LOOPBACK || (strcmp(ifi->ifi_name,"fxp4")==0)) {
Kristin Wright's avatar
Kristin Wright committed
66 67 68
		        continue;
		}

Kristin Wright's avatar
Kristin Wright committed
69 70 71 72 73
		/* We report this interface.
		 * That is, we put down the pair
		 * [ <myNodeID, ifi->haddr>, <0,0> ]
		 * for the [path, nbor] pair.
		 */
74
		/*
Kristin Wright's avatar
Kristin Wright committed
75
		nid = nw;
76
		nw += ETHADDRSIZ << 2; // we're writing 4 nodeids
Kristin Wright's avatar
Kristin Wright committed
77
		if ((char *)nw > mesg + mesglen ) { 
78 79
		        fprintf(stderr, "ran out of room and you didn't do anything
						reasonable.1\n");
Kristin Wright's avatar
Kristin Wright committed
80 81
			return 0;
		}
82 83
		//printf("My parent's address is:");
		//print_nodeID(parent_nodeIF);
Kristin Wright's avatar
Kristin Wright committed
84 85 86 87
		memcpy(nid, myNodeID, ETHADDRSIZ);
		nid += ETHADDRSIZ;
		memcpy(nid, ifi->ifi_haddr, ETHADDRSIZ);
		nid += ETHADDRSIZ;
88
		memcpy(nid,senderIF,ETHADDRSIZ);
89
		nid += ETHADDRSIZ;
90
		memcpy(nid,recverIF,ETHADDRSIZ);
91
		//bzero(nid, ETHADDRSIZ);
92
		*/
93 94 95 96 97
		if ( sendnbors != 0 ) {
		        while ( nborl != NULL ) {
		              nbor = (struct topd_nbor *)nw;
		              nw += nborl->tdnbl_n * sizeof(struct topd_nbor);
			      if ((char *)nw > mesg + mesglen ) {
98 99
			              fprintf(stderr, "ran out of room and you didn't do
								  anything reasonable.2\n");
100 101 102 103 104 105
				      return 0;
			      }
			      memcpy(nbor, nborl->tdnbl_nbors, nborl->tdnbl_n * sizeof(struct topd_nbor));
			      nborl = nborl->tdnbl_next;
			} 
		}
Kristin Wright's avatar
Kristin Wright committed
106
	}
107 108

	return (nw - mesg);
Kristin Wright's avatar
Kristin Wright committed
109
}