]>
Commit | Line | Data |
---|---|---|
7f57883e | 1 | /* |
b748db67 | 2 | * Eigrp Sending and Receiving EIGRP Reply Packets. |
7f57883e DS |
3 | * Copyright (C) 2013-2016 |
4 | * Authors: | |
5 | * Donnie Savage | |
6 | * Jan Janovic | |
7 | * Matej Perina | |
8 | * Peter Orsag | |
9 | * Peter Paluch | |
10 | * Frantisek Gazo | |
11 | * Tomas Hvorkovy | |
12 | * Martin Kontsek | |
13 | * Lukas Koribsky | |
14 | * | |
15 | * This file is part of GNU Zebra. | |
16 | * | |
17 | * GNU Zebra is free software; you can redistribute it and/or modify it | |
18 | * under the terms of the GNU General Public License as published by the | |
19 | * Free Software Foundation; either version 2, or (at your option) any | |
20 | * later version. | |
21 | * | |
22 | * GNU Zebra is distributed in the hope that it will be useful, but | |
23 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
24 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
25 | * General Public License for more details. | |
26 | * | |
896014f4 DL |
27 | * You should have received a copy of the GNU General Public License along |
28 | * with this program; see the file COPYING; if not, write to the Free Software | |
29 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
7f57883e DS |
30 | */ |
31 | ||
32 | #include <zebra.h> | |
33 | ||
34 | #include "thread.h" | |
35 | #include "memory.h" | |
36 | #include "linklist.h" | |
37 | #include "prefix.h" | |
38 | #include "if.h" | |
39 | #include "table.h" | |
40 | #include "sockunion.h" | |
41 | #include "stream.h" | |
42 | #include "log.h" | |
43 | #include "sockopt.h" | |
44 | #include "checksum.h" | |
45 | #include "md5.h" | |
46 | #include "vty.h" | |
47 | #include "keychain.h" | |
48 | #include "plist.h" | |
49 | ||
50 | #include "eigrpd/eigrp_structs.h" | |
51 | #include "eigrpd/eigrpd.h" | |
52 | #include "eigrpd/eigrp_interface.h" | |
53 | #include "eigrpd/eigrp_neighbor.h" | |
54 | #include "eigrpd/eigrp_packet.h" | |
55 | #include "eigrpd/eigrp_zebra.h" | |
56 | #include "eigrpd/eigrp_vty.h" | |
57 | #include "eigrpd/eigrp_dump.h" | |
58 | #include "eigrpd/eigrp_macros.h" | |
59 | #include "eigrpd/eigrp_topology.h" | |
60 | #include "eigrpd/eigrp_fsm.h" | |
8b0a80f1 | 61 | #include "eigrpd/eigrp_errors.h" |
7f57883e | 62 | |
dc4accdd DS |
63 | void eigrp_send_reply(struct eigrp_neighbor *nbr, |
64 | struct eigrp_prefix_descriptor *pe) | |
7f57883e | 65 | { |
d62a17ae | 66 | struct eigrp_packet *ep; |
d7c0a89a | 67 | uint16_t length = EIGRP_HEADER_LEN; |
71b52ef2 DS |
68 | struct eigrp_interface *ei = nbr->ei; |
69 | struct eigrp *eigrp = ei->eigrp; | |
dc4accdd | 70 | struct eigrp_prefix_descriptor *pe2; |
d62a17ae | 71 | |
72 | // TODO: Work in progress | |
73 | /* Filtering */ | |
74 | /* get list from eigrp process */ | |
dc4accdd DS |
75 | pe2 = XCALLOC(MTYPE_EIGRP_PREFIX_DESCRIPTOR, |
76 | sizeof(struct eigrp_prefix_descriptor)); | |
77 | memcpy(pe2, pe, sizeof(struct eigrp_prefix_descriptor)); | |
71b52ef2 | 78 | |
996c9314 | 79 | if (eigrp_update_prefix_apply(eigrp, ei, EIGRP_FILTER_OUT, |
71b52ef2 | 80 | pe2->destination)) { |
d62a17ae | 81 | zlog_info("REPLY SEND: Setting Metric to max"); |
82 | pe2->reported_metric.delay = EIGRP_MAX_METRIC; | |
d62a17ae | 83 | } |
84 | ||
85 | /* | |
86 | * End of filtering | |
87 | */ | |
88 | ||
9378632f | 89 | ep = eigrp_packet_new(EIGRP_PACKET_MTU(ei->ifp->mtu), nbr); |
d62a17ae | 90 | |
91 | /* Prepare EIGRP INIT UPDATE header */ | |
71b52ef2 DS |
92 | eigrp_packet_header_init(EIGRP_OPC_REPLY, eigrp, ep->s, 0, |
93 | eigrp->sequence_number, 0); | |
d62a17ae | 94 | |
95 | // encode Authentication TLV, if needed | |
b748db67 DS |
96 | if (ei->params.auth_type == EIGRP_AUTH_TYPE_MD5 |
97 | && (ei->params.auth_keychain != NULL)) { | |
71b52ef2 | 98 | length += eigrp_add_authTLV_MD5_to_stream(ep->s, ei); |
d62a17ae | 99 | } |
100 | ||
101 | ||
102 | length += eigrp_add_internalTLV_to_stream(ep->s, pe2); | |
103 | ||
b748db67 DS |
104 | if ((ei->params.auth_type == EIGRP_AUTH_TYPE_MD5) |
105 | && (ei->params.auth_keychain != NULL)) { | |
71b52ef2 | 106 | eigrp_make_md5_digest(ei, ep->s, EIGRP_AUTH_UPDATE_FLAG); |
d62a17ae | 107 | } |
108 | ||
109 | /* EIGRP Checksum */ | |
71b52ef2 | 110 | eigrp_packet_checksum(ei, ep->s, length); |
d62a17ae | 111 | |
112 | ep->length = length; | |
113 | ep->dst.s_addr = nbr->src.s_addr; | |
114 | ||
115 | /*This ack number we await from neighbor*/ | |
71b52ef2 | 116 | ep->sequence_number = eigrp->sequence_number; |
d62a17ae | 117 | |
118 | /*Put packet to retransmission queue*/ | |
f90f65a2 | 119 | eigrp_fifo_push(nbr->retrans_queue, ep); |
d62a17ae | 120 | |
121 | if (nbr->retrans_queue->count == 1) { | |
122 | eigrp_send_packet_reliably(nbr); | |
123 | } | |
124 | ||
dc4accdd | 125 | XFREE(MTYPE_EIGRP_PREFIX_DESCRIPTOR, pe2); |
7f57883e DS |
126 | } |
127 | ||
128 | /*EIGRP REPLY read function*/ | |
d62a17ae | 129 | void eigrp_reply_receive(struct eigrp *eigrp, struct ip *iph, |
130 | struct eigrp_header *eigrph, struct stream *s, | |
131 | struct eigrp_interface *ei, int size) | |
7f57883e | 132 | { |
d62a17ae | 133 | struct eigrp_neighbor *nbr; |
134 | struct TLV_IPv4_Internal_type *tlv; | |
135 | ||
d7c0a89a | 136 | uint16_t type; |
d62a17ae | 137 | |
138 | /* increment statistics. */ | |
139 | ei->reply_in++; | |
140 | ||
141 | /* get neighbor struct */ | |
142 | nbr = eigrp_nbr_get(ei, eigrph, iph); | |
143 | ||
144 | /* neighbor must be valid, eigrp_nbr_get creates if none existed */ | |
145 | assert(nbr); | |
146 | ||
147 | nbr->recv_sequence_number = ntohl(eigrph->sequence); | |
148 | ||
149 | while (s->endp > s->getp) { | |
150 | type = stream_getw(s); | |
b42a4a09 DS |
151 | |
152 | if (type != EIGRP_TLV_IPv4_INT) | |
153 | continue; | |
154 | ||
155 | struct prefix dest_addr; | |
156 | ||
d7c0a89a | 157 | stream_set_getp(s, s->getp - sizeof(uint16_t)); |
b42a4a09 DS |
158 | |
159 | tlv = eigrp_read_ipv4_tlv(s); | |
160 | ||
161 | dest_addr.family = AF_INET; | |
162 | dest_addr.u.prefix4 = tlv->destination; | |
163 | dest_addr.prefixlen = tlv->prefix_length; | |
dc4accdd | 164 | struct eigrp_prefix_descriptor *dest = |
996c9314 LB |
165 | eigrp_topology_table_lookup_ipv4(eigrp->topology_table, |
166 | &dest_addr); | |
b42a4a09 DS |
167 | /* |
168 | * Destination must exists | |
169 | */ | |
170 | if (!dest) { | |
1c50c1c0 QY |
171 | flog_err( |
172 | EC_EIGRP_PACKET, | |
2dbe669b DA |
173 | "%s: Received prefix %pFX which we do not know about", |
174 | __func__, &dest_addr); | |
2fd89ed7 | 175 | eigrp_IPv4_InternalTLV_free(tlv); |
b42a4a09 DS |
176 | continue; |
177 | } | |
178 | ||
179 | struct eigrp_fsm_action_message msg; | |
dc4accdd DS |
180 | struct eigrp_route_descriptor *entry = |
181 | eigrp_route_descriptor_lookup(dest->entries, nbr); | |
b42a4a09 | 182 | |
996c9314 | 183 | if (eigrp_update_prefix_apply(eigrp, ei, EIGRP_FILTER_IN, |
b42a4a09 DS |
184 | &dest_addr)) { |
185 | tlv->metric.delay = EIGRP_MAX_METRIC; | |
d62a17ae | 186 | } |
b42a4a09 DS |
187 | /* |
188 | * End of filtering | |
189 | */ | |
190 | ||
191 | msg.packet_type = EIGRP_OPC_REPLY; | |
192 | msg.eigrp = eigrp; | |
193 | msg.data_type = EIGRP_INT; | |
194 | msg.adv_router = nbr; | |
195 | msg.metrics = tlv->metric; | |
196 | msg.entry = entry; | |
197 | msg.prefix = dest; | |
198 | eigrp_fsm_event(&msg); | |
199 | ||
200 | eigrp_IPv4_InternalTLV_free(tlv); | |
d62a17ae | 201 | } |
202 | eigrp_hello_send_ack(nbr); | |
7f57883e | 203 | } |