]> git.proxmox.com Git - mirror_frr.git/blob - eigrpd/eigrp_query.c
*: make consistent & update GPLv2 file headers
[mirror_frr.git] / eigrpd / eigrp_query.c
1 /*
2 * EIGRP Sending and Receiving EIGRP Query Packets.
3 * Copyright (C) 2013-2014
4 * Authors:
5 * Donnie Savage
6 * Jan Janovic
7 * Matej Perina
8 * Peter Orsag
9 * Peter Paluch
10 *
11 * This file is part of GNU Zebra.
12 *
13 * GNU Zebra is free software; you can redistribute it and/or modify it
14 * under the terms of the GNU General Public License as published by the
15 * Free Software Foundation; either version 2, or (at your option) any
16 * later version.
17 *
18 * GNU Zebra is distributed in the hope that it will be useful, but
19 * WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 * General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License along
24 * with this program; see the file COPYING; if not, write to the Free Software
25 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
26 */
27
28 #include <zebra.h>
29
30 #include "thread.h"
31 #include "memory.h"
32 #include "linklist.h"
33 #include "prefix.h"
34 #include "if.h"
35 #include "table.h"
36 #include "sockunion.h"
37 #include "stream.h"
38 #include "log.h"
39 #include "sockopt.h"
40 #include "checksum.h"
41 #include "md5.h"
42 #include "vty.h"
43
44 #include "eigrpd/eigrp_structs.h"
45 #include "eigrpd/eigrpd.h"
46 #include "eigrpd/eigrp_interface.h"
47 #include "eigrpd/eigrp_neighbor.h"
48 #include "eigrpd/eigrp_packet.h"
49 #include "eigrpd/eigrp_zebra.h"
50 #include "eigrpd/eigrp_vty.h"
51 #include "eigrpd/eigrp_dump.h"
52 #include "eigrpd/eigrp_macros.h"
53 #include "eigrpd/eigrp_topology.h"
54 #include "eigrpd/eigrp_fsm.h"
55 #include "eigrpd/eigrp_memory.h"
56
57 u_int32_t
58 eigrp_query_send_all (struct eigrp *eigrp)
59 {
60 struct eigrp_interface *iface;
61 struct listnode *node, *node2, *nnode2;
62 struct eigrp_prefix_entry *pe;
63 u_int32_t counter;
64
65 if (eigrp == NULL)
66 {
67 zlog_debug("EIGRP Routing Process not enabled");
68 return 0;
69 }
70
71 counter=0;
72 for (ALL_LIST_ELEMENTS_RO(eigrp->eiflist, node, iface))
73 {
74 eigrp_send_query(iface);
75 counter++;
76 }
77
78 for (ALL_LIST_ELEMENTS(eigrp->topology_changes_internalIPV4, node2, nnode2, pe))
79 {
80 if(pe->req_action & EIGRP_FSM_NEED_QUERY)
81 {
82 pe->req_action &= ~EIGRP_FSM_NEED_QUERY;
83 listnode_delete(eigrp->topology_changes_internalIPV4, pe);
84 }
85 }
86
87 return counter;
88 }
89
90 /*EIGRP QUERY read function*/
91 void
92 eigrp_query_receive (struct eigrp *eigrp, struct ip *iph, struct eigrp_header *eigrph,
93 struct stream * s, struct eigrp_interface *ei, int size)
94 {
95 struct eigrp_neighbor *nbr;
96 struct TLV_IPv4_Internal_type *tlv;
97
98 u_int16_t type;
99
100 /* increment statistics. */
101 ei->query_in++;
102
103 /* get neighbor struct */
104 nbr = eigrp_nbr_get(ei, eigrph, iph);
105
106 /* neighbor must be valid, eigrp_nbr_get creates if none existed */
107 assert(nbr);
108
109 nbr->recv_sequence_number = ntohl(eigrph->sequence);
110
111 while (s->endp > s->getp)
112 {
113 type = stream_getw(s);
114 if (type == EIGRP_TLV_IPv4_INT)
115 {
116 stream_set_getp(s, s->getp - sizeof(u_int16_t));
117
118 tlv = eigrp_read_ipv4_tlv(s);
119
120 struct prefix_ipv4 *dest_addr;
121 dest_addr = prefix_ipv4_new();
122 dest_addr->prefix = tlv->destination;
123 dest_addr->prefixlen = tlv->prefix_length;
124 struct eigrp_prefix_entry *dest =
125 eigrp_topology_table_lookup_ipv4(eigrp->topology_table, dest_addr);
126
127 /* If the destination exists (it should, but one never know)*/
128 if (dest != NULL)
129 {
130 struct eigrp_fsm_action_message *msg;
131 msg = XCALLOC(MTYPE_EIGRP_FSM_MSG,
132 sizeof(struct eigrp_fsm_action_message));
133 struct eigrp_neighbor_entry *entry =
134 eigrp_prefix_entry_lookup(dest->entries, nbr);
135 msg->packet_type = EIGRP_OPC_QUERY;
136 msg->eigrp = eigrp;
137 msg->data_type = EIGRP_TLV_IPv4_INT;
138 msg->adv_router = nbr;
139 msg->data.ipv4_int_type = tlv;
140 msg->entry = entry;
141 msg->prefix = dest;
142 int event = eigrp_get_fsm_event(msg);
143 eigrp_fsm_event(msg, event);
144 }
145 eigrp_IPv4_InternalTLV_free (tlv);
146 }
147 }
148 eigrp_hello_send_ack(nbr);
149 eigrp_query_send_all(eigrp);
150 eigrp_update_send_all(eigrp,nbr->ei);
151 }
152
153 void
154 eigrp_send_query (struct eigrp_interface *ei)
155 {
156 struct eigrp_packet *ep;
157 u_int16_t length = EIGRP_HEADER_LEN;
158 struct listnode *node, *nnode, *node2, *nnode2;
159 struct eigrp_neighbor *nbr;
160 struct eigrp_prefix_entry *pe;
161 char has_tlv;
162
163 ep = eigrp_packet_new(ei->ifp->mtu);
164
165 /* Prepare EIGRP INIT UPDATE header */
166 eigrp_packet_header_init(EIGRP_OPC_QUERY, ei, ep->s, 0,
167 ei->eigrp->sequence_number, 0);
168
169 // encode Authentication TLV, if needed
170 if((IF_DEF_PARAMS (ei->ifp)->auth_type == EIGRP_AUTH_TYPE_MD5) &&
171 (IF_DEF_PARAMS (ei->ifp)->auth_keychain != NULL))
172 {
173 length += eigrp_add_authTLV_MD5_to_stream(ep->s,ei);
174 }
175
176 has_tlv = 0;
177 for (ALL_LIST_ELEMENTS(ei->eigrp->topology_changes_internalIPV4, node, nnode, pe))
178 {
179 if(pe->req_action & EIGRP_FSM_NEED_QUERY)
180 {
181 length += eigrp_add_internalTLV_to_stream(ep->s, pe);
182 for (ALL_LIST_ELEMENTS(ei->nbrs, node2, nnode2, nbr))
183 {
184 if(nbr->state == EIGRP_NEIGHBOR_UP)
185 {
186 listnode_add(pe->rij, nbr);
187 has_tlv = 1;
188 }
189 }
190 }
191 }
192
193 if(!has_tlv)
194 {
195 eigrp_packet_free(ep);
196 return;
197 }
198
199 if((IF_DEF_PARAMS (ei->ifp)->auth_type == EIGRP_AUTH_TYPE_MD5) &&
200 (IF_DEF_PARAMS (ei->ifp)->auth_keychain != NULL))
201 {
202 eigrp_make_md5_digest(ei,ep->s, EIGRP_AUTH_UPDATE_FLAG);
203 }
204
205 /* EIGRP Checksum */
206 eigrp_packet_checksum(ei, ep->s, length);
207
208 ep->length = length;
209 ep->dst.s_addr = htonl(EIGRP_MULTICAST_ADDRESS);
210
211 /*This ack number we await from neighbor*/
212 ep->sequence_number = ei->eigrp->sequence_number;
213
214 for (ALL_LIST_ELEMENTS(ei->nbrs, node2, nnode2, nbr))
215 {
216 if (nbr->state == EIGRP_NEIGHBOR_UP)
217 {
218 /*Put packet to retransmission queue*/
219 eigrp_fifo_push_head(nbr->retrans_queue, ep);
220
221 if (nbr->retrans_queue->count == 1)
222 {
223 eigrp_send_packet_reliably(nbr);
224 }
225 }
226 }
227 }