-
Notifications
You must be signed in to change notification settings - Fork 1
/
eigrp_query.c
202 lines (163 loc) · 5.25 KB
/
eigrp_query.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
// SPDX-License-Identifier: GPL-2.0-or-later
/*
* EIGRP Sending and Receiving EIGRP Query Packets.
* Copyright (C) 2013-2014
* Authors:
* Donnie Savage
* Jan Janovic
* Matej Perina
* Peter Orsag
* Peter Paluch
*/
#include "eigrpd/eigrpd.h"
#include "eigrpd/eigrp_structs.h"
#include "eigrpd/eigrp_topology.h"
#include "eigrpd/eigrp_interface.h"
#include "eigrpd/eigrp_neighbor.h"
#include "eigrpd/eigrp_packet.h"
#include "eigrpd/eigrp_auth.h"
#include "eigrpd/eigrp_fsm.h"
uint32_t eigrp_query_send_all(eigrp_instance_t *eigrp)
{
eigrp_interface_t *iface;
struct listnode *node, *node2, *nnode2;
eigrp_prefix_descriptor_t *prefix;
uint32_t counter;
counter = 0;
for (ALL_LIST_ELEMENTS_RO(eigrp->eiflist, node, iface)) {
eigrp_query_send(eigrp, iface);
counter++;
}
for (ALL_LIST_ELEMENTS(eigrp->topology_changes, node2, nnode2,
prefix)) {
if (prefix->req_action & EIGRP_FSM_NEED_QUERY) {
prefix->req_action &= ~EIGRP_FSM_NEED_QUERY;
listnode_delete(eigrp->topology_changes, prefix);
}
}
return counter;
}
/*EIGRP QUERY read function*/
void eigrp_query_receive(eigrp_instance_t *eigrp, eigrp_neighbor_t *nbr,
struct eigrp_header *eigrph, struct stream *pkt,
eigrp_interface_t *ei, int length)
{
eigrp_fsm_action_message_t msg;
eigrp_route_descriptor_t *route;
/* increment statistics. */
ei->stats.rcvd.query++;
/* get neighbor struct */
nbr->recv_sequence_number = ntohl(eigrph->sequence);
// process all TLVs in the packet
while (pkt->endp > pkt->getp) {
route = (nbr->tlv_decoder)(eigrp, nbr, pkt, length);
// should have got route off the packet, but one never know
if (route) {
msg.packet_type = EIGRP_OPC_QUERY;
msg.eigrp = eigrp;
msg.data_type = EIGRP_INT;
msg.adv_router = nbr;
msg.route = route;
msg.metrics = route->metric;
msg.prefix = route->prefix;
eigrp_fsm_event(&msg);
} else {
// neighbor sent corrupted packet - flush remaining
// packet
break;
}
}
eigrp_hello_send_ack(nbr);
eigrp_query_send_all(eigrp);
eigrp_update_send_all(eigrp, nbr->ei);
}
void eigrp_query_send(eigrp_instance_t *eigrp, eigrp_interface_t *ei)
{
eigrp_packet_t *packet = NULL;
eigrp_neighbor_t *nbr;
eigrp_prefix_descriptor_t *prefix;
eigrp_route_descriptor_t *route;
uint16_t length = EIGRP_HEADER_LEN;
struct listnode *node, *nnode, *node2, *nnode2;
struct list *successors;
bool has_tlv = false;
bool new_packet = true;
uint16_t eigrp_mtu = EIGRP_PACKET_MTU(ei->ifp->mtu);
for (ALL_LIST_ELEMENTS(ei->eigrp->topology_changes, node, nnode, prefix)) {
if (!(prefix->req_action & EIGRP_FSM_NEED_QUERY))
continue;
if (new_packet) {
packet = eigrp_packet_new(eigrp_mtu, NULL);
/* Prepare EIGRP INIT UPDATE header */
eigrp_packet_header_init(EIGRP_OPC_QUERY, ei->eigrp,
packet->s, 0,
ei->eigrp->sequence_number, 0);
// encode Authentication TLV, if needed
if ((ei->params.auth_type == EIGRP_AUTH_TYPE_MD5)
&& (ei->params.auth_keychain != NULL)) {
length +=
eigrp_add_authTLV_MD5_encode(packet->s, ei);
}
new_packet = false;
}
// grab the route from the prefix so we can get the metrics we need
successors = eigrp_topology_get_successor(prefix);
assert(successors); // If this is NULL somebody poked us in the eye.
route = listnode_head(successors);
length += (nbr->tlv_encoder)(eigrp, nbr, packet->s, route);
has_tlv = true;
for (ALL_LIST_ELEMENTS(ei->nbrs, node2, nnode2, nbr)) {
if (nbr->state == EIGRP_NEIGHBOR_UP)
listnode_add(prefix->rij, nbr);
}
if (length + EIGRP_TLV_MAX_IPV4_BYTE > eigrp_mtu) {
if ((ei->params.auth_type == EIGRP_AUTH_TYPE_MD5)
&& ei->params.auth_keychain != NULL) {
eigrp_make_md5_digest(ei, packet->s, EIGRP_AUTH_UPDATE_FLAG);
}
eigrp_packet_checksum(ei, packet->s, length);
packet->length = length;
packet->dst.ip.v4.s_addr = htonl(EIGRP_MULTICAST_ADDRESS);
packet->sequence_number = ei->eigrp->sequence_number;
ei->eigrp->sequence_number++;
for (ALL_LIST_ELEMENTS(ei->nbrs, node2, nnode2, nbr)) {
eigrp_packet_t *dup;
if (nbr->state != EIGRP_NEIGHBOR_UP)
continue;
dup = eigrp_packet_duplicate(packet, nbr);
/*Put packet to retransmission queue*/
eigrp_packet_enqueue(nbr->retrans_queue, dup);
if (nbr->retrans_queue->count == 1)
eigrp_packet_send_reliably(eigrp, nbr);
}
has_tlv = false;
length = 0;
eigrp_packet_free(packet);
packet = NULL;
new_packet = true;
}
}
if (!has_tlv)
return;
if ((ei->params.auth_type == EIGRP_AUTH_TYPE_MD5)
&& ei->params.auth_keychain != NULL)
eigrp_make_md5_digest(ei, packet->s, EIGRP_AUTH_UPDATE_FLAG);
/* EIGRP Checksum */
eigrp_packet_checksum(ei, packet->s, length);
packet->length = length;
packet->dst.ip.v4.s_addr = htonl(EIGRP_MULTICAST_ADDRESS);
/*This ack number we await from neighbor*/
packet->sequence_number = ei->eigrp->sequence_number;
ei->eigrp->sequence_number++;
for (ALL_LIST_ELEMENTS(ei->nbrs, node2, nnode2, nbr)) {
eigrp_packet_t *dup;
if (nbr->state != EIGRP_NEIGHBOR_UP)
continue;
dup = eigrp_packet_duplicate(packet, nbr);
/*Put packet to retransmission queue*/
eigrp_packet_enqueue(nbr->retrans_queue, dup);
if (nbr->retrans_queue->count == 1)
eigrp_packet_send_reliably(eigrp, nbr);
}
eigrp_packet_free(packet);
}