2 * The olsr.org Optimized Link-State Routing daemon(olsrd)
3 * Copyright (c) 2004, Andreas Tønnesen(andreto@olsr.org)
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
16 * * Neither the name of olsr.org, olsrd nor the names of its
17 * contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
26 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
30 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 * POSSIBILITY OF SUCH DAMAGE.
33 * Visit http://www.olsr.org for more information.
35 * If you find this software useful feel free to make a donation
36 * to the project. For more information see the website or contact
37 * the copyright holders.
41 #include "rebuild_packet.h"
50 *Process/rebuild MID message. Converts the OLSR
51 *packet to the internal mid_message format.
52 *@param mmsg the mid_message struct in wich infomation
54 *@param m the entire OLSR message revieved.
55 *@return negative on error
59 mid_chgestruct(struct mid_message *mmsg, const union olsr_message *m)
62 struct mid_alias *alias, *alias_tmp;
65 /* Checking if everything is ok */
66 if ((!m) || (m->v4.olsr_msgtype != MID_MESSAGE))
71 if(olsr_cnf->ip_version == AF_INET)
74 const struct midaddr *maddr = m->v4.message.mid.mid_addr;
77 * nextmsg contains size of
78 * the addresses + 12 bytes(nextmessage, from address and the header)
80 no_aliases = ((ntohs(m->v4.olsr_msgsize) - 12) / 4);
82 /*printf("Aliases: %d\n", no_aliases); */
83 mmsg->mid_origaddr.v4.s_addr = m->v4.originator;
84 mmsg->addr.v4.s_addr = m->v4.originator;
86 mmsg->mid_seqno = ntohs(m->v4.seqno);
87 mmsg->mid_addr = NULL;
90 mmsg->vtime = me_to_reltime(m->v4.olsr_vtime);
92 /*printf("Sequencenuber of MID from %s is %d\n", ip_to_string(&mmsg->addr), mmsg->mid_seqno); */
95 for(i = 0; i < no_aliases; i++)
97 alias = olsr_malloc(sizeof(struct mid_alias), "MID chgestruct");
99 alias->alias_addr.v4.s_addr = maddr->addr;
100 alias->next = mmsg->mid_addr;
101 mmsg->mid_addr = alias;
106 if(olsr_cnf->debug_level > 1)
108 struct ipaddr_str buf;
109 OLSR_PRINTF(3, "Alias list for %s: ", olsr_ip_to_string(&buf, &mmsg->mid_origaddr));
110 OLSR_PRINTF(3, "%s", olsr_ip_to_string(&buf, &mmsg->addr));
111 alias_tmp = mmsg->mid_addr;
114 OLSR_PRINTF(3, " - %s", olsr_ip_to_string(&buf, &alias_tmp->alias_addr));
115 alias_tmp = alias_tmp->next;
117 OLSR_PRINTF(3, "\n");
123 const struct midaddr6 *maddr6 = m->v6.message.mid.mid_addr;
126 * nextmsg contains size of
127 * the addresses + 12 bytes(nextmessage, from address and the header)
129 no_aliases = ((ntohs(m->v6.olsr_msgsize) - 12) / 16); /* NB 16 */
131 /*printf("Aliases: %d\n", no_aliases); */
132 mmsg->mid_origaddr.v6 = m->v6.originator;
133 mmsg->addr.v6 = m->v6.originator;
135 mmsg->mid_seqno = ntohs(m->v6.seqno);
136 mmsg->mid_addr = NULL;
139 mmsg->vtime = me_to_reltime(m->v6.olsr_vtime);
141 /*printf("Sequencenuber of MID from %s is %d\n", ip_to_string(&mmsg->addr), mmsg->mid_seqno); */
143 for(i = 0; i < no_aliases; i++)
145 alias = olsr_malloc(sizeof(struct mid_alias), "MID chgestruct 2");
147 /*printf("Adding alias: %s\n", olsr_ip_to_string(&buf, (union olsr_ip_addr *)&maddr6->addr));*/
148 alias->alias_addr.v6 = maddr6->addr;
149 alias->next = mmsg->mid_addr;
150 mmsg->mid_addr = alias;
156 if(olsr_cnf->debug_level > 1)
158 struct ipaddr_str buf;
159 OLSR_PRINTF(3, "Alias list for %s", ip6_to_string(&buf, &mmsg->mid_origaddr.v6));
160 OLSR_PRINTF(3, "%s", ip6_to_string(&buf, &mmsg->addr.v6));
162 alias_tmp = mmsg->mid_addr;
165 OLSR_PRINTF(3, " - %s", ip6_to_string(&buf, &alias_tmp->alias_addr.v6));
166 alias_tmp = alias_tmp->next;
168 OLSR_PRINTF(3, "\n");
178 *Process/rebuild a message of unknown type. Converts the OLSR
179 *packet to the internal unknown_message format.
180 *@param umsg the unknown_message struct in wich infomation
182 *@param m the entire OLSR message revieved.
183 *@return negative on error
187 unk_chgestruct(struct unknown_message *umsg, const union olsr_message *m)
190 /* Checking if everything is ok */
195 if(olsr_cnf->ip_version == AF_INET)
199 umsg->originator.v4.s_addr = m->v4.originator;
201 umsg->seqno = ntohs(m->v4.seqno);
203 umsg->type = m->v4.olsr_msgtype;
209 umsg->originator.v6 = m->v6.originator;
211 umsg->seqno = ntohs(m->v6.seqno);
213 umsg->type = m->v4.olsr_msgtype;