2 * OLSR ad-hoc routing table management protocol
3 * Copyright (C) 2004 Andreas Tønnesen (andreto@ifi.uio.no)
5 * This file is part of the olsr.org OLSR daemon.
7 * olsr.org is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * olsr.org is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with olsr.org; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 * $Id: build_msg.c,v 1.16 2004/10/19 20:18:00 kattemat Exp $
28 #include "build_msg.h"
29 #include "local_hna_set.h"
33 /* All these functions share this buffer */
35 static char msg_buffer[MAXMESSAGESIZE - OLSR_HEADERSIZE];
38 * Prototypes for internal functions
44 hello_build4(struct hello_message *, struct interface *);
47 tc_build4(struct tc_message *, struct interface *);
50 mid_build4(struct interface *);
53 hna_build4(struct interface *);
58 hello_build6(struct hello_message *, struct interface *);
61 tc_build6(struct tc_message *, struct interface *);
64 mid_build6(struct interface *);
67 hna_build6(struct interface *);
70 * Prototypes for internal functions
77 * These are the functions to call from outside
82 * Generate HELLO packet with the contents of the parameter "message".
83 * If this won't fit in one packet, chop it up into several.
84 * Send the packet if the size of the data contained in the output buffer
85 * reach maxmessagesize. Can generate an empty HELLO packet if the
86 * neighbor table is empty. The parameter messag is not used.
89 *@param message the hello_message struct containing the info
90 *to build the hello message from.
91 *@param ifp the interface to send the message on
97 hello_build(struct hello_message *message, struct interface *ifp)
99 switch(olsr_cnf->ip_version)
102 hello_build4(message, ifp);
105 hello_build6(message, ifp);
115 * Generate TC packet with the contents of the parameter "message".
116 * If this won't fit in one packet, chop it up into several.
117 * Send the packet if the size of the data contained in the output buffer
118 * reach maxmessagesize. Don't generate an empty TC packet.
119 * The parameter messag is not used.
121 *If parameter ifp = NULL then this is a TC packet who is to be
122 *forwarded. In that case each chump of the packet(if bigger then
123 *maxmessagesize the packet has to be split) must be forwarded
124 *on each interface(exept the one it came on - if it was a wired interface)
125 *and seqnumbers must be taken from the recieved packet.
127 *@param message the tc_message struct containing the info
129 *@param ifp the interface to send the message on
135 tc_build(struct tc_message *message, struct interface *ifp)
137 switch(olsr_cnf->ip_version)
140 tc_build4(message, ifp);
143 tc_build6(message, ifp);
153 *Build a MID message to the outputbuffer
155 *<b>NO INTERNAL BUFFER</b>
156 *@param ifn use this interfaces address as main address
157 *@return 1 on success
161 mid_build(struct interface *ifn)
163 switch(olsr_cnf->ip_version)
179 *Builds a HNA message in the outputbuffer
180 *<b>NB! Not internal packetformat!</b>
182 *@param ifp the interface to send on
186 hna_build(struct interface *ifp)
188 switch(olsr_cnf->ip_version)
203 * Protocol specific versions
212 *@param message the hello_message struct containing the info
213 *to build the hello message from.
214 *@param ifp the interface to send the message on
220 hello_build4(struct hello_message *message, struct interface *ifp)
222 int remainsize, curr_size;
223 struct hello_neighbor *nb, *prev_nb;
224 union olsr_message *m;
226 struct hellinfo *hinfo;
227 union olsr_ip_addr *haddr;
229 int lastpacket = 0; /* number of neighbors with the same
230 greater link status in the last packet */
231 if((!message) || (!ifp) || (olsr_cnf->ip_version != AF_INET))
234 remainsize = net_outbuffer_bytes_left(ifp);
236 //printf("HELLO build outputsize: %d\n", outputsize);
238 m = (union olsr_message *)msg_buffer;
240 curr_size = 12; /* OLSR message header */
241 curr_size += 4; /* Hello header */
243 /* Send pending packet if not room in buffer */
244 if(curr_size > remainsize)
247 remainsize = net_outbuffer_bytes_left(ifp);
250 h = &m->v4.message.hello;
251 hinfo = h->hell_info;
252 haddr = (union olsr_ip_addr *)hinfo->neigh_addr;
254 //printf("Neighbor addr: %s\n", olsr_ip_to_string(haddr));fflush(stdout);
256 /* Fill message header */
257 m->v4.ttl = message->ttl;
259 m->v4.olsr_msgtype = HELLO_MESSAGE;
260 /* Set source(main) addr */
261 COPY_IP(&m->v4.originator, &main_addr);
263 m->v4.olsr_vtime = ifp->valtimes.hello;
265 /* Fill HELLO header */
266 h->willingness = message->willingness;
267 h->htime = ifp->hello_etime;
269 memset(&h->reserved, 0, sizeof(olsr_u16_t));
273 *Loops trough all possible neighbor statuses
274 *The negbor list is grouped by status
277 /* Nighbor statuses */
278 for (i = 0; i <= MAX_NEIGH; i++)
281 for(j = 0; j <= MAX_LINK; j++)
286 *Not adding neighbors with link type HIDE
292 lastpacket = sametype = 0;
294 //printf("Neighbortype %d outputsize %d\n", i, outputsize);
297 *Looping trough neighbors
299 for (nb = message->neighbors; nb != NULL; nb = nb->next)
301 if ((nb->status == i) && (nb->link == j))
308 * If there is not enough room left
309 * for the data in tho outputbuffer
310 * we must send a partial HELLO and
311 * continue building the rest of the
312 * data in a new HELLO message
313 * Add ipsize in check since there is
314 * no use sending just the type header
316 if((curr_size + 4 + ipsize) > remainsize)
318 /* Only send partial HELLO if it contains data */
319 if(curr_size > (12 + 4))
321 /* Complete the headers */
322 m->v4.seqno = htons(get_msg_seqno());
323 m->v4.olsr_msgsize = htons(curr_size);
325 hinfo->size = (char *)haddr - (char *)hinfo;
326 hinfo->size = ntohs(hinfo->size);
328 /* Send partial packet */
329 net_outbuffer_push(ifp, msg_buffer, curr_size);
331 curr_size = 12; /* OLSR message header */
332 curr_size += 4; /* Hello header */
334 h = &m->v4.message.hello;
335 hinfo = h->hell_info;
336 haddr = (union olsr_ip_addr *)hinfo->neigh_addr;
340 /* Reset size and pointers */
341 remainsize = net_outbuffer_bytes_left(ifp);
343 memset(&hinfo->reserved, 0, sizeof(olsr_u8_t));
344 /* Set link and status for this group of neighbors (this is the first) */
345 hinfo->link_code = CREATE_LINK_CODE(i, j);//j | (i<<2);
346 //printf("(2)Setting neighbor link status: %x\n", hinfo->link_code);
347 curr_size += 4; /* HELLO type section header */
351 olsr_printf(5, "\tLink status of %s: ", olsr_ip_to_string(&nb->address));
352 olsr_printf(5, "%d\n", nb->link);
356 * If there is not enough room left
357 * for the data in tho outputbuffer
358 * we must send a partial HELLO and
359 * continue building the rest of the
360 * data in a new HELLO message
362 if((curr_size + ipsize) > remainsize)
364 /* If we get here the message contains data
367 /* Complete the headers */
368 m->v4.seqno = htons(get_msg_seqno());
369 m->v4.olsr_msgsize = htons(curr_size);
371 hinfo->size = (char *)haddr - (char *)hinfo;
372 hinfo->size = ntohs(hinfo->size);
374 /* Send partial packet */
375 net_outbuffer_push(ifp, msg_buffer, curr_size);
378 /* Reset size and pointers */
379 remainsize = net_outbuffer_bytes_left(ifp);
380 curr_size = 12; /* OLSR message header */
381 curr_size += 4; /* Hello header */
383 h = &m->v4.message.hello;
384 hinfo = h->hell_info;
385 haddr = (union olsr_ip_addr *)hinfo->neigh_addr;
387 /* Rebuild TYPE header */
388 memset(&hinfo->reserved, 0, sizeof(olsr_u8_t));
389 /* Set link and status for this group of neighbors (this is the first) */
390 hinfo->link_code = CREATE_LINK_CODE(i, j);//j | (i<<2);
391 //printf("(2)Setting neighbor link status: %x\n", hinfo->link_code);
392 curr_size += 4; /* HELLO type section header */
396 COPY_IP(haddr, &nb->address);
398 //printf("\n\n1: %d\n", (char *)haddr - packet);
400 *Point to next address
402 haddr = (union olsr_ip_addr *)&haddr->v6.s6_addr[4];
403 curr_size += ipsize; /* IP address added */
405 //printf("\n2: %d\n\n", (char *)haddr - packet);
406 //printf("Ipsize: %d\n", ipsize);
408 //printf("Adding neighbor %s\n", olsr_ip_to_string(&nb->address));
412 }/* looping trough neighbors */
415 if (sametype && sametype > lastpacket)
417 hinfo->size = (char *)haddr - (char *)hinfo;
418 hinfo->size = ntohs(hinfo->size);
419 hinfo = (struct hellinfo *)((char *)haddr);
420 haddr = (union olsr_ip_addr *)&hinfo->neigh_addr;
426 m->v4.seqno = htons(get_msg_seqno());
427 m->v4.olsr_msgsize = htons(curr_size);
429 net_outbuffer_push(ifp, msg_buffer, curr_size);
432 * Delete the list of neighbor messages.
435 nb = message->neighbors;
452 *@param message the hello_message struct containing the info
453 *to build the hello message from.
454 *@param ifp the interface to send the message on
461 hello_build6(struct hello_message *message, struct interface *ifp)
463 int remainsize, curr_size;
464 struct hello_neighbor *nb, *prev_nb;
465 union olsr_message *m;
466 struct hellomsg6 *h6;
467 struct hellinfo6 *hinfo6;
468 union olsr_ip_addr *haddr;
471 int lastpacket = 0; /* number of neighbors with the same
472 greater link status in the last packet */
473 if((!message) || (!ifp) || (olsr_cnf->ip_version != AF_INET6))
477 remainsize = net_outbuffer_bytes_left(ifp);
479 //printf("HELLO build outputsize: %d\n", outputsize);
481 m = (union olsr_message *)msg_buffer;
483 curr_size = 24; /* OLSR message header */
484 curr_size += 4; /* Hello header */
486 /* Send pending packet if not room in buffer */
487 if(curr_size > remainsize)
490 remainsize = net_outbuffer_bytes_left(ifp);
493 //printf("HELLO build outputsize: %d\n", outputsize);
494 h6 = &m->v6.message.hello;
495 hinfo6 = h6->hell_info;
496 haddr = (union olsr_ip_addr *)hinfo6->neigh_addr;
499 /* Fill message header */
500 m->v6.ttl = message->ttl;
502 /* Set source(main) addr */
503 COPY_IP(&m->v6.originator, &main_addr);
504 m->v6.olsr_msgtype = HELLO_MESSAGE;
506 m->v6.olsr_vtime = ifp->valtimes.hello;
508 /* Fill packet header */
509 h6->willingness = message->willingness;
511 h6->htime = ifp->hello_etime;
513 memset(&h6->reserved, 0, sizeof(olsr_u16_t));
518 *Loops trough all possible neighbor statuses
519 *The negbor list is grouped by status
522 for (i = 0; i <= MAX_NEIGH; i++)
524 for(j = 0; j <= MAX_LINK; j++)
528 lastpacket = sametype = 0;
531 //printf("Neighbortype %d outputsize %d\n", i, outputsize);
534 *Looping trough neighbors
536 for (nb = message->neighbors; nb != NULL; nb = nb->next)
538 if ((nb->status == i) && (nb->link == j))
543 /* Check if there is room for header + one address */
544 if((curr_size + 4 + ipsize) > remainsize)
546 /* Only send partial HELLO if it contains data */
547 if(curr_size > (24 + 4))
549 /* Complete the headers */
550 m->v6.seqno = htons(get_msg_seqno());
551 m->v6.olsr_msgsize = htons(curr_size);
553 hinfo6->size = (char *)haddr - (char *)hinfo6;
554 hinfo6->size = ntohs(hinfo6->size);
556 /* Send partial packet */
557 net_outbuffer_push(ifp, msg_buffer, curr_size);
558 curr_size = 24; /* OLSR message header */
559 curr_size += 4; /* Hello header */
561 h6 = &m->v6.message.hello;
562 hinfo6 = h6->hell_info;
563 haddr = (union olsr_ip_addr *)hinfo6->neigh_addr;
566 /* Reset size and pointers */
567 remainsize = net_outbuffer_bytes_left(ifp);
569 memset(&hinfo6->reserved, 0, sizeof(olsr_u8_t));
570 /* Set link and status for this group of neighbors (this is the first) */
571 hinfo6->link_code = CREATE_LINK_CODE(i, j);//j | (i<<2);
572 //printf("(2)Setting neighbor link status: %x\n", hinfo->link_code);
573 curr_size += 4; /* HELLO type section header */
577 olsr_printf(5, "\tLink status of %s: ", olsr_ip_to_string(&nb->address));
578 olsr_printf(5, "%d\n", nb->link);
582 * If there is not enough room left
583 * for the data in the outputbuffer
584 * we must send a partial HELLO and
585 * continue building the rest of the
586 * data in a new HELLO message
588 if((curr_size + ipsize) > remainsize)
590 /* If we get here the message contains data
593 /* Complete the headers */
594 m->v6.seqno = htons(get_msg_seqno());
595 m->v6.olsr_msgsize = htons(curr_size);
597 hinfo6->size = (char *)haddr - (char *)hinfo6;
598 hinfo6->size = ntohs(hinfo6->size);
600 /* Send partial packet */
601 net_outbuffer_push(ifp, msg_buffer, curr_size);
602 curr_size = 24; /* OLSR message header */
603 curr_size += 4; /* Hello header */
605 h6 = &m->v6.message.hello;
606 hinfo6 = h6->hell_info;
607 haddr = (union olsr_ip_addr *)hinfo6->neigh_addr;
609 /* Rebuild TYPE header */
610 memset(&hinfo6->reserved, 0, sizeof(olsr_u8_t));
611 /* Set link and status for this group of neighbors (this is the first) */
612 hinfo6->link_code = CREATE_LINK_CODE(i, j);//j | (i<<2);
613 //printf("(2)Setting neighbor link status: %x\n", hinfo->link_code);
614 curr_size += 4; /* HELLO type section header */
618 remainsize = net_outbuffer_bytes_left(ifp);
622 COPY_IP(haddr, &nb->address);
624 //printf("\n\n1: %d\n", (char *)haddr - packet);
626 *Point to next address
629 curr_size += ipsize; /* IP address added */
630 //printf("\n2: %d\n\n", (char *)haddr - packet);
631 //printf("Ipsize: %d\n", ipsize);
633 //printf("Adding neighbor %s\n", olsr_ip_to_string(&nb->address));
637 }/* looping trough neighbors */
640 if (sametype && sametype > lastpacket)
642 hinfo6->size = (char *)haddr - (char *)hinfo6;
643 hinfo6->size = ntohs(hinfo6->size);
644 hinfo6 = (struct hellinfo6 *)((char *)haddr);
645 haddr = (union olsr_ip_addr *)&hinfo6->neigh_addr;
651 m->v6.seqno = htons(get_msg_seqno());
652 m->v6.olsr_msgsize = htons(curr_size);
654 net_outbuffer_push(ifp, msg_buffer, curr_size);
657 * Delete the list of neighbor messages.
660 nb = message->neighbors;
678 *@param message the tc_message struct containing the info
680 *@param ifp the interface to send the message on
686 tc_build4(struct tc_message *message, struct interface *ifp)
689 int remainsize, curr_size;;
690 struct tc_mpr_addr *mprs, *prev_mprs;
691 union olsr_message *m;
693 struct neigh_info *mprsaddr;
694 int found = 0, partial_sent = 0;
696 if((!message) || (!ifp) || (olsr_cnf->ip_version != AF_INET))
699 remainsize = net_outbuffer_bytes_left(ifp);
701 m = (union olsr_message *)msg_buffer;
703 tc = &m->v4.message.tc;
706 mprsaddr = tc->neigh;
707 curr_size = 12; /* OLSR message header */
708 curr_size += 4; /* TC header */
710 /* Send pending packet if not room in buffer */
711 if(curr_size > remainsize)
714 remainsize = net_outbuffer_bytes_left(ifp);
718 m->v4.olsr_vtime = ifp->valtimes.tc;
719 m->v4.olsr_msgtype = TC_MESSAGE;
720 m->v4.hopcnt = message->hop_count;
721 m->v4.ttl = message->ttl;
722 COPY_IP(&m->v4.originator, &message->originator);
725 tc->ansn = htons(message->ansn);
729 /*Looping trough MPR selectors */
730 for (mprs = message->multipoint_relay_selector_address; mprs != NULL;mprs = mprs->next)
732 /*If packet is to be chomped */
733 if((curr_size + ipsize) > remainsize)
736 /* Only add TC message if it contains data */
737 if(curr_size > (12 + 4 ))
739 m->v4.olsr_msgsize = htons(curr_size);
740 m->v4.seqno = htons(get_msg_seqno());
742 net_outbuffer_push(ifp, msg_buffer, curr_size);
745 mprsaddr = tc->neigh;
746 curr_size = 12; /* OLSR message header */
747 curr_size += 4; /* TC header */
753 remainsize = net_outbuffer_bytes_left(ifp);
758 COPY_IP(&mprsaddr->addr, &mprs->address);
767 m->v4.olsr_msgsize = htons(curr_size);
768 m->v4.seqno = htons(get_msg_seqno());
770 net_outbuffer_push(ifp, msg_buffer, curr_size);
775 if((!partial_sent) && (!TIMED_OUT(&send_empty_tc)))
777 olsr_printf(1, "TC: Sending empty package\n");
779 m->v4.olsr_msgsize = htons(curr_size);
780 m->v4.seqno = htons(get_msg_seqno());
782 net_outbuffer_push(ifp, msg_buffer, curr_size);
789 * Delete the list of mprs messages
792 mprs = message->multipoint_relay_selector_address;
810 *@param message the tc_message struct containing the info
812 *@param ifp the interface to send the message on
818 tc_build6(struct tc_message *message, struct interface *ifp)
821 int remainsize, curr_size;;
822 struct tc_mpr_addr *mprs, *prev_mprs;
823 union olsr_message *m;
825 struct neigh_info6 *mprsaddr6;
826 int found = 0, partial_sent = 0;
828 if ((!message) || (!ifp) || (olsr_cnf->ip_version != AF_INET6))
831 remainsize = net_outbuffer_bytes_left(ifp);
833 m = (union olsr_message *)msg_buffer;
835 tc6 = &m->v6.message.tc;
837 mprsaddr6 = tc6->neigh;
838 curr_size = 24; /* OLSR message header */
839 curr_size += 4; /* TC header */
841 /* Send pending packet if not room in buffer */
842 if(curr_size > remainsize)
845 remainsize = net_outbuffer_bytes_left(ifp);
849 m->v6.olsr_vtime = ifp->valtimes.tc;
850 m->v6.olsr_msgtype = TC_MESSAGE;
851 m->v6.hopcnt = message->hop_count;
852 m->v6.ttl = message->ttl;
853 COPY_IP(&m->v6.originator, &message->originator);
856 tc6->ansn = htons(message->ansn);
860 /*Looping trough MPR selectors */
861 for (mprs = message->multipoint_relay_selector_address; mprs != NULL;mprs = mprs->next)
864 /*If packet is to be chomped */
865 if((curr_size + ipsize) > remainsize)
867 /* Only add TC message if it contains data */
868 if(curr_size > (24 + 4 ))
870 m->v6.olsr_msgsize = htons(curr_size);
871 m->v6.seqno = htons(get_msg_seqno());
873 net_outbuffer_push(ifp, msg_buffer, curr_size);
874 mprsaddr6 = tc6->neigh;
875 curr_size = 24; /* OLSR message header */
876 curr_size += 4; /* TC header */
881 remainsize = net_outbuffer_bytes_left(ifp);
887 //printf("mprsaddr6 is %x\n", (char *)mprsaddr6 - packet);
888 //printf("Adding MPR-selector: %s\n", olsr_ip_to_string(&mprs->address));fflush(stdout);
889 COPY_IP(&mprsaddr6->addr, &mprs->address);
897 m->v6.olsr_msgsize = htons(curr_size);
898 m->v6.seqno = htons(get_msg_seqno());
900 net_outbuffer_push(ifp, msg_buffer, curr_size);
905 if((!partial_sent) && (!TIMED_OUT(&send_empty_tc)))
907 olsr_printf(1, "TC: Sending empty package\n");
909 m->v6.olsr_msgsize = htons(curr_size);
910 m->v6.seqno = htons(get_msg_seqno());
912 net_outbuffer_push(ifp, msg_buffer, curr_size);
917 * Delete the list of mprs messages
920 mprs = message->multipoint_relay_selector_address;
938 *<b>NO INTERNAL BUFFER</b>
939 *@param ifp use this interfaces address as main address
940 *@return 1 on success
944 mid_build4(struct interface *ifp)
946 int remainsize, curr_size;
947 /* preserve existing data in output buffer */
948 union olsr_message *m;
949 struct midaddr *addrs;
950 struct interface *ifs;
952 if((olsr_cnf->ip_version != AF_INET) || (!ifp) || (ifnet == NULL || ifnet->int_next == NULL))
956 remainsize = net_outbuffer_bytes_left(ifp);
958 m = (union olsr_message *)msg_buffer;
960 curr_size = 12; /* OLSR message header */
962 /* Send pending packet if not room in buffer */
963 if(curr_size > remainsize)
966 remainsize = net_outbuffer_bytes_left(ifp);
972 /* Set main(first) address */
973 COPY_IP(&m->v4.originator, &main_addr);
974 m->v4.olsr_msgtype = MID_MESSAGE;
975 m->v4.olsr_vtime = ifp->valtimes.mid;
977 addrs = m->v4.message.mid.mid_addr;
979 /* Don't add the main address... it's already there */
980 for(ifs = ifnet; ifs != NULL; ifs = ifs->int_next)
982 if(!COMP_IP(&main_addr, &ifs->ip_addr))
985 if((curr_size + ipsize) > remainsize)
987 /* Only add MID message if it contains data */
991 m->v4.olsr_msgsize = htons(curr_size);
992 m->v4.seqno = htons(get_msg_seqno());/* seqnumber */
994 net_outbuffer_push(ifp, msg_buffer, curr_size);
995 curr_size = 12; /* OLSR message header */
996 addrs = m->v4.message.mid.mid_addr;
999 remainsize = net_outbuffer_bytes_left(ifp);
1002 COPY_IP(&addrs->addr, &ifs->ip_addr);
1004 curr_size += ipsize;
1009 m->v4.seqno = htons(get_msg_seqno());/* seqnumber */
1010 m->v4.olsr_msgsize = htons(curr_size);
1012 //printf("Sending MID (%d bytes)...\n", outputsize);
1013 net_outbuffer_push(ifp, msg_buffer, curr_size);
1024 *<b>NO INTERNAL BUFFER</b>
1025 *@param ifp use this interfaces address as main address
1026 *@return 1 on success
1030 mid_build6(struct interface *ifp)
1032 int remainsize, curr_size;
1033 /* preserve existing data in output buffer */
1034 union olsr_message *m;
1035 struct midaddr6 *addrs6;
1036 struct interface *ifs;
1038 //printf("\t\tGenerating mid on %s\n", ifn->int_name);
1041 if((olsr_cnf->ip_version != AF_INET6) || (!ifp) || (ifnet == NULL || ifnet->int_next == NULL))
1044 remainsize = net_outbuffer_bytes_left(ifp);
1046 curr_size = 24; /* OLSR message header */
1048 /* Send pending packet if not room in buffer */
1049 if(curr_size > remainsize)
1052 remainsize = net_outbuffer_bytes_left(ifp);
1055 m = (union olsr_message *)msg_buffer;
1059 m->v6.ttl = MAX_TTL;
1060 m->v6.olsr_msgtype = MID_MESSAGE;
1061 m->v6.olsr_vtime = ifp->valtimes.mid;
1062 /* Set main(first) address */
1063 COPY_IP(&m->v6.originator, &main_addr);
1066 addrs6 = m->v6.message.mid.mid_addr;
1068 /* Don't add the main address... it's already there */
1069 for(ifs = ifnet; ifs != NULL; ifs = ifs->int_next)
1071 if(!COMP_IP(&main_addr, &ifs->ip_addr))
1073 if((curr_size + ipsize) > remainsize)
1075 /* Only add MID message if it contains data */
1079 m->v6.olsr_msgsize = htons(curr_size);
1080 m->v6.seqno = htons(get_msg_seqno());/* seqnumber */
1082 net_outbuffer_push(ifp, msg_buffer, curr_size);
1083 curr_size = 24; /* OLSR message header */
1084 addrs6 = m->v6.message.mid.mid_addr;
1087 remainsize = net_outbuffer_bytes_left(ifp);
1090 COPY_IP(&addrs6->addr, &ifs->ip_addr);
1092 curr_size += ipsize;
1096 m->v6.olsr_msgsize = htons(curr_size);
1097 m->v6.seqno = htons(get_msg_seqno());/* seqnumber */
1099 //printf("Sending MID (%d bytes)...\n", outputsize);
1100 net_outbuffer_push(ifp, msg_buffer, curr_size);
1111 *@param ifp the interface to send on
1115 hna_build4(struct interface *ifp)
1117 int remainsize, curr_size;
1118 /* preserve existing data in output buffer */
1119 union olsr_message *m;
1120 struct hnapair *pair;
1121 struct hna4_entry *h = olsr_cnf->hna4_entries;
1124 if((olsr_cnf->ip_version != AF_INET) || (!ifp) || h == NULL)
1127 remainsize = net_outbuffer_bytes_left(ifp);
1129 curr_size = 12; /* OLSR message header */
1131 /* Send pending packet if not room in buffer */
1132 if(curr_size > remainsize)
1135 remainsize = net_outbuffer_bytes_left(ifp);
1138 m = (union olsr_message *)msg_buffer;
1142 COPY_IP(&m->v4.originator, &main_addr);
1144 m->v4.ttl = MAX_TTL;
1145 m->v4.olsr_msgtype = HNA_MESSAGE;
1146 m->v4.olsr_vtime = ifp->valtimes.hna;
1149 pair = m->v4.message.hna.hna_net;
1153 if((curr_size + (2 * ipsize)) > remainsize)
1155 /* Only add HNA message if it contains data */
1158 m->v4.seqno = htons(get_msg_seqno());
1159 m->v4.olsr_msgsize = htons(curr_size);
1160 net_outbuffer_push(ifp, msg_buffer, curr_size);
1161 curr_size = 12; /* OLSR message header */
1162 pair = m->v4.message.hna.hna_net;
1165 remainsize = net_outbuffer_bytes_left(ifp);
1167 COPY_IP(&pair->addr, &h->net);
1168 COPY_IP(&pair->netmask, &h->netmask);
1170 curr_size += (2 * ipsize);
1174 m->v4.seqno = htons(get_msg_seqno());
1175 m->v4.olsr_msgsize = htons(curr_size);
1177 net_outbuffer_push(ifp, msg_buffer, curr_size);
1179 //printf("Sending HNA (%d bytes)...\n", outputsize);
1190 *@param ifp the interface to send on
1194 hna_build6(struct interface *ifp)
1196 int remainsize, curr_size;
1197 /* preserve existing data in output buffer */
1198 union olsr_message *m;
1199 struct hnapair6 *pair6;
1200 union olsr_ip_addr tmp_netmask;
1201 struct hna6_entry *h = olsr_cnf->hna6_entries;
1204 if((olsr_cnf->ip_version != AF_INET6) || (!ifp) || h == NULL)
1208 remainsize = net_outbuffer_bytes_left(ifp);
1210 curr_size = 24; /* OLSR message header */
1212 /* Send pending packet if not room in buffer */
1213 if(curr_size > remainsize)
1216 remainsize = net_outbuffer_bytes_left(ifp);
1219 m = (union olsr_message *)msg_buffer;
1222 COPY_IP(&m->v6.originator, &main_addr);
1224 m->v6.ttl = MAX_TTL;
1225 m->v6.olsr_msgtype = HNA_MESSAGE;
1226 m->v6.olsr_vtime = ifp->valtimes.hna;
1228 pair6 = m->v6.message.hna.hna_net;
1233 if((curr_size + (2 * ipsize)) > remainsize)
1235 /* Only add HNA message if it contains data */
1238 m->v6.seqno = htons(get_msg_seqno());
1239 m->v6.olsr_msgsize = htons(curr_size);
1240 net_outbuffer_push(ifp, msg_buffer, curr_size);
1241 curr_size = 24; /* OLSR message header */
1242 pair6 = m->v6.message.hna.hna_net;
1245 remainsize = net_outbuffer_bytes_left(ifp);
1248 //printf("Adding %s\n", olsr_ip_to_string(&h->hna_net.addr));
1249 COPY_IP(&pair6->addr, &h->net);
1250 olsr_prefix_to_netmask(&tmp_netmask, h->prefix_len);
1251 COPY_IP(&pair6->netmask, &tmp_netmask);
1253 curr_size += (2 * ipsize);
1257 m->v6.olsr_msgsize = htons(curr_size);
1258 m->v6.seqno = htons(get_msg_seqno());
1260 net_outbuffer_push(ifp, msg_buffer, curr_size);
1262 //printf("Sending HNA (%d bytes)...\n", outputsize);