reply.c 3.58 KB
Newer Older
Kristin Wright's avatar
Kristin Wright committed
1 2
/* 
 * Copyright (c) 2000 The University of Utah and the Flux Group.
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
 * 
 * {{{EMULAB-LICENSE
 * 
 * This file is part of the Emulab network testbed software.
 * 
 * This file is free software: you can redistribute it and/or modify it
 * under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or (at
 * your option) any later version.
 * 
 * This file is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public
 * License for more details.
 * 
 * You should have received a copy of the GNU Affero General Public License
 * along with this file.  If not, see <http://www.gnu.org/licenses/>.
 * 
 * }}}
Kristin Wright's avatar
Kristin Wright committed
22 23 24 25 26 27 28 29
 *
 * ---------------------------
 *
 * Filename: reply.c
 *   -- Author: Kristin Wright <kwright@cs.utah.edu> 
 *
 * ---------------------------
 *
Mike Hibler's avatar
Mike Hibler committed
30
 * $Id: reply.c,v 1.11 2004-06-17 18:17:01 mike Exp $
Kristin Wright's avatar
Kristin Wright committed
31 32 33 34 35
 */


#include "discvr.h"
#include "packet.h"
36
#include "util.h"
Kristin Wright's avatar
Kristin Wright committed
37 38

extern u_char myNodeID[ETHADDRSIZ];
39
//extern u_char parent_nodeIF[ETHADDRSIZ];
Kristin Wright's avatar
Kristin Wright committed
40
extern topd_inqid_t inqid_current;
41
//extern u_char receivingIF[ETHADDRSIZ];
Kristin Wright's avatar
Kristin Wright committed
42 43 44 45 46
/*
 * Concatenate all the individual interfaces' messages into
 * one long neighbor list.
 */
u_int32_t
47 48
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
49
{
Kristin Wright's avatar
Kristin Wright committed
50 51 52 53 54
        struct topd_nborlist *nborl;
	struct ifi_info      *ifihead;
        char                 *nw;
	char                 *nid;
	struct topd_nbor     *nbor;
Kristin Wright's avatar
Kristin Wright committed
55 56 57 58 59 60 61

	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);

62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
	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
77
	for (ifihead = ifi; ifi != NULL; ifi = ifi->ifi_next) {
Kristin Wright's avatar
Kristin Wright committed
78 79
	        nborl  = ifi->ifi_nbors;

Kristin Wright's avatar
Kristin Wright committed
80 81
	        /* Add check for control net -LKW */
	        if (ifi->ifi_flags & !IFF_UP || 
82
		    ifi->ifi_flags & IFF_LOOPBACK || (strcmp(ifi->ifi_name,"fxp4")==0)) {
Kristin Wright's avatar
Kristin Wright committed
83 84 85
		        continue;
		}

Kristin Wright's avatar
Kristin Wright committed
86 87 88 89 90
		/* We report this interface.
		 * That is, we put down the pair
		 * [ <myNodeID, ifi->haddr>, <0,0> ]
		 * for the [path, nbor] pair.
		 */
91
		/*
Kristin Wright's avatar
Kristin Wright committed
92
		nid = nw;
93
		nw += ETHADDRSIZ << 2; // we're writing 4 nodeids
Kristin Wright's avatar
Kristin Wright committed
94
		if ((char *)nw > mesg + mesglen ) { 
95 96
		        fprintf(stderr, "ran out of room and you didn't do anything
						reasonable.1\n");
Kristin Wright's avatar
Kristin Wright committed
97 98
			return 0;
		}
99 100
		//printf("My parent's address is:");
		//print_nodeID(parent_nodeIF);
Kristin Wright's avatar
Kristin Wright committed
101 102 103 104
		memcpy(nid, myNodeID, ETHADDRSIZ);
		nid += ETHADDRSIZ;
		memcpy(nid, ifi->ifi_haddr, ETHADDRSIZ);
		nid += ETHADDRSIZ;
105
		memcpy(nid,senderIF,ETHADDRSIZ);
106
		nid += ETHADDRSIZ;
107
		memcpy(nid,recverIF,ETHADDRSIZ);
108
		//bzero(nid, ETHADDRSIZ);
109
		*/
110 111 112 113 114
		if ( sendnbors != 0 ) {
		        while ( nborl != NULL ) {
		              nbor = (struct topd_nbor *)nw;
		              nw += nborl->tdnbl_n * sizeof(struct topd_nbor);
			      if ((char *)nw > mesg + mesglen ) {
115 116
			              fprintf(stderr, "ran out of room and you didn't do
								  anything reasonable.2\n");
117 118 119 120 121 122
				      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
123
	}
124 125

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