]> git.proxmox.com Git - mirror_frr.git/blame - eigrpd/eigrp_query.c
Merge pull request #1051 from donaldsharp/plists
[mirror_frr.git] / eigrpd / eigrp_query.c
CommitLineData
7f57883e
DS
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 *
896014f4
DL
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
7f57883e
DS
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
d62a17ae 57u_int32_t eigrp_query_send_all(struct eigrp *eigrp)
7f57883e 58{
d62a17ae 59 struct eigrp_interface *iface;
60 struct listnode *node, *node2, *nnode2;
61 struct eigrp_prefix_entry *pe;
62 u_int32_t counter;
63
64 if (eigrp == NULL) {
65 zlog_debug("EIGRP Routing Process not enabled");
66 return 0;
67 }
68
69 counter = 0;
70 for (ALL_LIST_ELEMENTS_RO(eigrp->eiflist, node, iface)) {
71 eigrp_send_query(iface);
72 counter++;
73 }
74
75 for (ALL_LIST_ELEMENTS(eigrp->topology_changes_internalIPV4, node2,
76 nnode2, pe)) {
77 if (pe->req_action & EIGRP_FSM_NEED_QUERY) {
78 pe->req_action &= ~EIGRP_FSM_NEED_QUERY;
79 listnode_delete(eigrp->topology_changes_internalIPV4,
80 pe);
81 }
82 }
83
84 return counter;
7f57883e
DS
85}
86
87/*EIGRP QUERY read function*/
d62a17ae 88void eigrp_query_receive(struct eigrp *eigrp, struct ip *iph,
89 struct eigrp_header *eigrph, struct stream *s,
90 struct eigrp_interface *ei, int size)
7f57883e 91{
d62a17ae 92 struct eigrp_neighbor *nbr;
93 struct TLV_IPv4_Internal_type *tlv;
476a1469 94 struct prefix dest_addr;
d62a17ae 95
96 u_int16_t type;
c283f389 97 u_int16_t length;
d62a17ae 98
99 /* increment statistics. */
100 ei->query_in++;
101
102 /* get neighbor struct */
103 nbr = eigrp_nbr_get(ei, eigrph, iph);
104
105 /* neighbor must be valid, eigrp_nbr_get creates if none existed */
106 assert(nbr);
107
108 nbr->recv_sequence_number = ntohl(eigrph->sequence);
109
110 while (s->endp > s->getp) {
111 type = stream_getw(s);
c283f389
DS
112 switch (type) {
113 case EIGRP_TLV_IPv4_INT:
d62a17ae 114 stream_set_getp(s, s->getp - sizeof(u_int16_t));
115
116 tlv = eigrp_read_ipv4_tlv(s);
117
118 dest_addr.family = AF_INET;
476a1469 119 dest_addr.u.prefix4 = tlv->destination;
d62a17ae 120 dest_addr.prefixlen = tlv->prefix_length;
121 struct eigrp_prefix_entry *dest =
122 eigrp_topology_table_lookup_ipv4(
123 eigrp->topology_table, &dest_addr);
124
125 /* If the destination exists (it should, but one never
126 * know)*/
127 if (dest != NULL) {
92035b1d 128 struct eigrp_fsm_action_message msg;
d62a17ae 129 struct eigrp_neighbor_entry *entry =
130 eigrp_prefix_entry_lookup(dest->entries,
131 nbr);
92035b1d
DS
132 msg.packet_type = EIGRP_OPC_QUERY;
133 msg.eigrp = eigrp;
7cfa4322 134 msg.data_type = EIGRP_INT;
92035b1d 135 msg.adv_router = nbr;
db6ec9ff 136 msg.metrics = tlv->metric;
92035b1d
DS
137 msg.entry = entry;
138 msg.prefix = dest;
6118272f 139 eigrp_fsm_event(&msg);
d62a17ae 140 }
141 eigrp_IPv4_InternalTLV_free(tlv);
c283f389
DS
142 break;
143
144 case EIGRP_TLV_IPv4_EXT:
145 /* DVS: processing of external routes needs packet and fsm work.
146 * for now, lets just not creash the box
147 */
148 default:
149 length = stream_getw(s);
150 // -2 for type, -2 for len
151 for (length-=4; length ; length--) {
152 (void)stream_getc(s);
153 }
d62a17ae 154 }
155 }
156 eigrp_hello_send_ack(nbr);
157 eigrp_query_send_all(eigrp);
158 eigrp_update_send_all(eigrp, nbr->ei);
7f57883e
DS
159}
160
d62a17ae 161void eigrp_send_query(struct eigrp_interface *ei)
7f57883e 162{
d62a17ae 163 struct eigrp_packet *ep;
164 u_int16_t length = EIGRP_HEADER_LEN;
165 struct listnode *node, *nnode, *node2, *nnode2;
166 struct eigrp_neighbor *nbr;
167 struct eigrp_prefix_entry *pe;
168 char has_tlv;
169 bool ep_saved = false;
170
907b4303 171 ep = eigrp_packet_new(ei->ifp->mtu, NULL);
d62a17ae 172
173 /* Prepare EIGRP INIT UPDATE header */
cf2f4dae 174 eigrp_packet_header_init(EIGRP_OPC_QUERY, ei->eigrp, ep->s, 0,
d62a17ae 175 ei->eigrp->sequence_number, 0);
176
177 // encode Authentication TLV, if needed
178 if ((IF_DEF_PARAMS(ei->ifp)->auth_type == EIGRP_AUTH_TYPE_MD5)
179 && (IF_DEF_PARAMS(ei->ifp)->auth_keychain != NULL)) {
180 length += eigrp_add_authTLV_MD5_to_stream(ep->s, ei);
181 }
182
183 has_tlv = 0;
184 for (ALL_LIST_ELEMENTS(ei->eigrp->topology_changes_internalIPV4, node,
185 nnode, pe)) {
186 if (pe->req_action & EIGRP_FSM_NEED_QUERY) {
187 length += eigrp_add_internalTLV_to_stream(ep->s, pe);
188 for (ALL_LIST_ELEMENTS(ei->nbrs, node2, nnode2, nbr)) {
189 if (nbr->state == EIGRP_NEIGHBOR_UP) {
190 listnode_add(pe->rij, nbr);
191 has_tlv = 1;
192 }
193 }
194 }
195 }
196
197 if (!has_tlv) {
198 eigrp_packet_free(ep);
199 return;
200 }
201
202 if ((IF_DEF_PARAMS(ei->ifp)->auth_type == EIGRP_AUTH_TYPE_MD5)
203 && (IF_DEF_PARAMS(ei->ifp)->auth_keychain != NULL)) {
204 eigrp_make_md5_digest(ei, ep->s, EIGRP_AUTH_UPDATE_FLAG);
205 }
206
207 /* EIGRP Checksum */
208 eigrp_packet_checksum(ei, ep->s, length);
209
210 ep->length = length;
211 ep->dst.s_addr = htonl(EIGRP_MULTICAST_ADDRESS);
212
213 /*This ack number we await from neighbor*/
214 ep->sequence_number = ei->eigrp->sequence_number;
215
216 for (ALL_LIST_ELEMENTS(ei->nbrs, node2, nnode2, nbr)) {
217 if (nbr->state == EIGRP_NEIGHBOR_UP) {
218 /*Put packet to retransmission queue*/
f90f65a2 219 eigrp_fifo_push(nbr->retrans_queue, ep);
d62a17ae 220 ep_saved = true;
221
222 if (nbr->retrans_queue->count == 1) {
223 eigrp_send_packet_reliably(nbr);
224 }
225 }
226 }
227
228 if (!ep_saved)
229 eigrp_packet_free(ep);
7f57883e 230}