]> git.proxmox.com Git - mirror_frr.git/blob - eigrpd/eigrp_query.c
eigrp: Initial Commit
[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
24 * along with GNU Zebra; see the file COPYING. If not, write to the Free
25 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
26 * 02111-1307, USA.
27 */
28
29 #include <zebra.h>
30
31 #include "thread.h"
32 #include "memory.h"
33 #include "linklist.h"
34 #include "prefix.h"
35 #include "if.h"
36 #include "table.h"
37 #include "sockunion.h"
38 #include "stream.h"
39 #include "log.h"
40 #include "sockopt.h"
41 #include "checksum.h"
42 #include "md5.h"
43 #include "vty.h"
44
45 #include "eigrpd/eigrp_structs.h"
46 #include "eigrpd/eigrpd.h"
47 #include "eigrpd/eigrp_interface.h"
48 #include "eigrpd/eigrp_neighbor.h"
49 #include "eigrpd/eigrp_packet.h"
50 #include "eigrpd/eigrp_zebra.h"
51 #include "eigrpd/eigrp_vty.h"
52 #include "eigrpd/eigrp_dump.h"
53 #include "eigrpd/eigrp_macros.h"
54 #include "eigrpd/eigrp_topology.h"
55 #include "eigrpd/eigrp_fsm.h"
56 #include "eigrpd/eigrp_memory.h"
57
58 u_int32_t
59 eigrp_query_send_all (struct eigrp *eigrp)
60 {
61 struct eigrp_interface *iface;
62 struct listnode *node, *node2, *nnode2;
63 struct eigrp_prefix_entry *pe;
64 u_int32_t counter;
65
66 if (eigrp == NULL)
67 {
68 zlog_debug("EIGRP Routing Process not enabled");
69 return 0;
70 }
71
72 counter=0;
73 for (ALL_LIST_ELEMENTS_RO(eigrp->eiflist, node, iface))
74 {
75 eigrp_send_query(iface);
76 counter++;
77 }
78
79 for (ALL_LIST_ELEMENTS(eigrp->topology_changes_internalIPV4, node2, nnode2, pe))
80 {
81 if(pe->req_action & EIGRP_FSM_NEED_QUERY)
82 {
83 pe->req_action &= ~EIGRP_FSM_NEED_QUERY;
84 listnode_delete(eigrp->topology_changes_internalIPV4, pe);
85 }
86 }
87
88 return counter;
89 }
90
91 /*EIGRP QUERY read function*/
92 void
93 eigrp_query_receive (struct eigrp *eigrp, struct ip *iph, struct eigrp_header *eigrph,
94 struct stream * s, struct eigrp_interface *ei, int size)
95 {
96 struct eigrp_neighbor *nbr;
97 struct TLV_IPv4_Internal_type *tlv;
98
99 u_int16_t type;
100
101 /* increment statistics. */
102 ei->query_in++;
103
104 /* get neighbor struct */
105 nbr = eigrp_nbr_get(ei, eigrph, iph);
106
107 /* neighbor must be valid, eigrp_nbr_get creates if none existed */
108 assert(nbr);
109
110 nbr->recv_sequence_number = ntohl(eigrph->sequence);
111
112 while (s->endp > s->getp)
113 {
114 type = stream_getw(s);
115 if (type == EIGRP_TLV_IPv4_INT)
116 {
117 stream_set_getp(s, s->getp - sizeof(u_int16_t));
118
119 tlv = eigrp_read_ipv4_tlv(s);
120
121 struct prefix_ipv4 *dest_addr;
122 dest_addr = prefix_ipv4_new();
123 dest_addr->prefix = tlv->destination;
124 dest_addr->prefixlen = tlv->prefix_length;
125 struct eigrp_prefix_entry *dest = eigrp_topology_table_lookup_ipv4(
126 eigrp->topology_table, dest_addr);
127
128 /* If the destination exists (it should, but one never know)*/
129 if (dest != NULL)
130 {
131 struct eigrp_fsm_action_message *msg;
132 msg = XCALLOC(MTYPE_EIGRP_FSM_MSG,
133 sizeof(struct eigrp_fsm_action_message));
134 struct eigrp_neighbor_entry *entry = eigrp_prefix_entry_lookup(
135 dest->entries, nbr);
136 msg->packet_type = EIGRP_OPC_QUERY;
137 msg->eigrp = eigrp;
138 msg->data_type = EIGRP_TLV_IPv4_INT;
139 msg->adv_router = nbr;
140 msg->data.ipv4_int_type = tlv;
141 msg->entry = entry;
142 msg->prefix = dest;
143 int event = eigrp_get_fsm_event(msg);
144 eigrp_fsm_event(msg, event);
145 }
146 eigrp_IPv4_InternalTLV_free (tlv);
147 }
148 }
149 eigrp_hello_send_ack(nbr);
150 eigrp_query_send_all(eigrp);
151 eigrp_update_send_all(eigrp,nbr->ei);
152 }
153
154 void
155 eigrp_send_query (struct eigrp_interface *ei)
156 {
157 struct eigrp_packet *ep;
158 u_int16_t length = EIGRP_HEADER_LEN;
159 struct listnode *node, *nnode, *node2, *nnode2;
160 struct eigrp_neighbor *nbr;
161 struct eigrp_prefix_entry *pe;
162 char has_tlv;
163
164 ep = eigrp_packet_new(ei->ifp->mtu);
165
166 /* Prepare EIGRP INIT UPDATE header */
167 eigrp_packet_header_init(EIGRP_OPC_QUERY, ei, ep->s, 0,
168 ei->eigrp->sequence_number, 0);
169
170 // encode Authentication TLV, if needed
171 if((IF_DEF_PARAMS (ei->ifp)->auth_type == EIGRP_AUTH_TYPE_MD5) && (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) && (IF_DEF_PARAMS (ei->ifp)->auth_keychain != NULL))
200 {
201 eigrp_make_md5_digest(ei,ep->s, EIGRP_AUTH_UPDATE_FLAG);
202 }
203
204 /* EIGRP Checksum */
205 eigrp_packet_checksum(ei, ep->s, length);
206
207 ep->length = length;
208 ep->dst.s_addr = htonl(EIGRP_MULTICAST_ADDRESS);
209
210 /*This ack number we await from neighbor*/
211 ep->sequence_number = ei->eigrp->sequence_number;
212
213 for (ALL_LIST_ELEMENTS(ei->nbrs, node2, nnode2, nbr))
214 {
215 if (nbr->state == EIGRP_NEIGHBOR_UP)
216 {
217 /*Put packet to retransmission queue*/
218 eigrp_fifo_push_head(nbr->retrans_queue, ep);
219
220 if (nbr->retrans_queue->count == 1)
221 {
222 eigrp_send_packet_reliably(nbr);
223 }
224 }
225 }
226 }