]> git.proxmox.com Git - mirror_frr.git/blob - eigrpd/eigrp_query.c
*: reindent
[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 eigrp_query_send_all(struct eigrp *eigrp)
58 {
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;
85 }
86
87 /*EIGRP QUERY read function*/
88 void eigrp_query_receive(struct eigrp *eigrp, struct ip *iph,
89 struct eigrp_header *eigrph, struct stream *s,
90 struct eigrp_interface *ei, int size)
91 {
92 struct eigrp_neighbor *nbr;
93 struct TLV_IPv4_Internal_type *tlv;
94
95 u_int16_t type;
96
97 /* increment statistics. */
98 ei->query_in++;
99
100 /* get neighbor struct */
101 nbr = eigrp_nbr_get(ei, eigrph, iph);
102
103 /* neighbor must be valid, eigrp_nbr_get creates if none existed */
104 assert(nbr);
105
106 nbr->recv_sequence_number = ntohl(eigrph->sequence);
107
108 while (s->endp > s->getp) {
109 type = stream_getw(s);
110 if (type == EIGRP_TLV_IPv4_INT) {
111 struct prefix_ipv4 dest_addr;
112
113 stream_set_getp(s, s->getp - sizeof(u_int16_t));
114
115 tlv = eigrp_read_ipv4_tlv(s);
116
117 dest_addr.family = AF_INET;
118 dest_addr.prefix = tlv->destination;
119 dest_addr.prefixlen = tlv->prefix_length;
120 struct eigrp_prefix_entry *dest =
121 eigrp_topology_table_lookup_ipv4(
122 eigrp->topology_table, &dest_addr);
123
124 /* If the destination exists (it should, but one never
125 * know)*/
126 if (dest != NULL) {
127 struct eigrp_fsm_action_message *msg;
128 msg = XCALLOC(MTYPE_EIGRP_FSM_MSG,
129 sizeof(struct
130 eigrp_fsm_action_message));
131 struct eigrp_neighbor_entry *entry =
132 eigrp_prefix_entry_lookup(dest->entries,
133 nbr);
134 msg->packet_type = EIGRP_OPC_QUERY;
135 msg->eigrp = eigrp;
136 msg->data_type = EIGRP_TLV_IPv4_INT;
137 msg->adv_router = nbr;
138 msg->data.ipv4_int_type = tlv;
139 msg->entry = entry;
140 msg->prefix = dest;
141 int event = eigrp_get_fsm_event(msg);
142 eigrp_fsm_event(msg, event);
143 }
144 eigrp_IPv4_InternalTLV_free(tlv);
145 }
146 }
147 eigrp_hello_send_ack(nbr);
148 eigrp_query_send_all(eigrp);
149 eigrp_update_send_all(eigrp, nbr->ei);
150 }
151
152 void eigrp_send_query(struct eigrp_interface *ei)
153 {
154 struct eigrp_packet *ep;
155 u_int16_t length = EIGRP_HEADER_LEN;
156 struct listnode *node, *nnode, *node2, *nnode2;
157 struct eigrp_neighbor *nbr;
158 struct eigrp_prefix_entry *pe;
159 char has_tlv;
160 bool ep_saved = false;
161
162 ep = eigrp_packet_new(ei->ifp->mtu);
163
164 /* Prepare EIGRP INIT UPDATE header */
165 eigrp_packet_header_init(EIGRP_OPC_QUERY, ei, ep->s, 0,
166 ei->eigrp->sequence_number, 0);
167
168 // encode Authentication TLV, if needed
169 if ((IF_DEF_PARAMS(ei->ifp)->auth_type == EIGRP_AUTH_TYPE_MD5)
170 && (IF_DEF_PARAMS(ei->ifp)->auth_keychain != NULL)) {
171 length += eigrp_add_authTLV_MD5_to_stream(ep->s, ei);
172 }
173
174 has_tlv = 0;
175 for (ALL_LIST_ELEMENTS(ei->eigrp->topology_changes_internalIPV4, node,
176 nnode, pe)) {
177 if (pe->req_action & EIGRP_FSM_NEED_QUERY) {
178 length += eigrp_add_internalTLV_to_stream(ep->s, pe);
179 for (ALL_LIST_ELEMENTS(ei->nbrs, node2, nnode2, nbr)) {
180 if (nbr->state == EIGRP_NEIGHBOR_UP) {
181 listnode_add(pe->rij, nbr);
182 has_tlv = 1;
183 }
184 }
185 }
186 }
187
188 if (!has_tlv) {
189 eigrp_packet_free(ep);
190 return;
191 }
192
193 if ((IF_DEF_PARAMS(ei->ifp)->auth_type == EIGRP_AUTH_TYPE_MD5)
194 && (IF_DEF_PARAMS(ei->ifp)->auth_keychain != NULL)) {
195 eigrp_make_md5_digest(ei, ep->s, EIGRP_AUTH_UPDATE_FLAG);
196 }
197
198 /* EIGRP Checksum */
199 eigrp_packet_checksum(ei, ep->s, length);
200
201 ep->length = length;
202 ep->dst.s_addr = htonl(EIGRP_MULTICAST_ADDRESS);
203
204 /*This ack number we await from neighbor*/
205 ep->sequence_number = ei->eigrp->sequence_number;
206
207 for (ALL_LIST_ELEMENTS(ei->nbrs, node2, nnode2, nbr)) {
208 if (nbr->state == EIGRP_NEIGHBOR_UP) {
209 /*Put packet to retransmission queue*/
210 eigrp_fifo_push_head(nbr->retrans_queue, ep);
211 ep_saved = true;
212
213 if (nbr->retrans_queue->count == 1) {
214 eigrp_send_packet_reliably(nbr);
215 }
216 }
217 }
218
219 if (!ep_saved)
220 eigrp_packet_free(ep);
221 }