]> git.proxmox.com Git - mirror_frr.git/blob - eigrpd/eigrp_query.c
Merge pull request #1008 from donaldsharp/check_for_daemon_existence
[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 struct prefix_ipv4 dest_addr;
95
96 u_int16_t type;
97 u_int16_t length;
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);
112 switch (type) {
113 case EIGRP_TLV_IPv4_INT:
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;
119 dest_addr.prefix = tlv->destination;
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) {
128 struct eigrp_fsm_action_message *msg;
129 msg = XCALLOC(MTYPE_EIGRP_FSM_MSG,
130 sizeof(struct
131 eigrp_fsm_action_message));
132 struct eigrp_neighbor_entry *entry =
133 eigrp_prefix_entry_lookup(dest->entries,
134 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 break;
147
148 case EIGRP_TLV_IPv4_EXT:
149 /* DVS: processing of external routes needs packet and fsm work.
150 * for now, lets just not creash the box
151 */
152 default:
153 length = stream_getw(s);
154 // -2 for type, -2 for len
155 for (length-=4; length ; length--) {
156 (void)stream_getc(s);
157 }
158 }
159 }
160 eigrp_hello_send_ack(nbr);
161 eigrp_query_send_all(eigrp);
162 eigrp_update_send_all(eigrp, nbr->ei);
163 }
164
165 void eigrp_send_query(struct eigrp_interface *ei)
166 {
167 struct eigrp_packet *ep;
168 u_int16_t length = EIGRP_HEADER_LEN;
169 struct listnode *node, *nnode, *node2, *nnode2;
170 struct eigrp_neighbor *nbr;
171 struct eigrp_prefix_entry *pe;
172 char has_tlv;
173 bool ep_saved = false;
174
175 ep = eigrp_packet_new(ei->ifp->mtu, NULL);
176
177 /* Prepare EIGRP INIT UPDATE header */
178 eigrp_packet_header_init(EIGRP_OPC_QUERY, ei->eigrp, ep->s, 0,
179 ei->eigrp->sequence_number, 0);
180
181 // encode Authentication TLV, if needed
182 if ((IF_DEF_PARAMS(ei->ifp)->auth_type == EIGRP_AUTH_TYPE_MD5)
183 && (IF_DEF_PARAMS(ei->ifp)->auth_keychain != NULL)) {
184 length += eigrp_add_authTLV_MD5_to_stream(ep->s, ei);
185 }
186
187 has_tlv = 0;
188 for (ALL_LIST_ELEMENTS(ei->eigrp->topology_changes_internalIPV4, node,
189 nnode, pe)) {
190 if (pe->req_action & EIGRP_FSM_NEED_QUERY) {
191 length += eigrp_add_internalTLV_to_stream(ep->s, pe);
192 for (ALL_LIST_ELEMENTS(ei->nbrs, node2, nnode2, nbr)) {
193 if (nbr->state == EIGRP_NEIGHBOR_UP) {
194 listnode_add(pe->rij, nbr);
195 has_tlv = 1;
196 }
197 }
198 }
199 }
200
201 if (!has_tlv) {
202 eigrp_packet_free(ep);
203 return;
204 }
205
206 if ((IF_DEF_PARAMS(ei->ifp)->auth_type == EIGRP_AUTH_TYPE_MD5)
207 && (IF_DEF_PARAMS(ei->ifp)->auth_keychain != NULL)) {
208 eigrp_make_md5_digest(ei, ep->s, EIGRP_AUTH_UPDATE_FLAG);
209 }
210
211 /* EIGRP Checksum */
212 eigrp_packet_checksum(ei, ep->s, length);
213
214 ep->length = length;
215 ep->dst.s_addr = htonl(EIGRP_MULTICAST_ADDRESS);
216
217 /*This ack number we await from neighbor*/
218 ep->sequence_number = ei->eigrp->sequence_number;
219
220 for (ALL_LIST_ELEMENTS(ei->nbrs, node2, nnode2, nbr)) {
221 if (nbr->state == EIGRP_NEIGHBOR_UP) {
222 /*Put packet to retransmission queue*/
223 eigrp_fifo_push(nbr->retrans_queue, ep);
224 ep_saved = true;
225
226 if (nbr->retrans_queue->count == 1) {
227 eigrp_send_packet_reliably(nbr);
228 }
229 }
230 }
231
232 if (!ep_saved)
233 eigrp_packet_free(ep);
234 }