]> git.proxmox.com Git - mirror_frr.git/blob - eigrpd/eigrp_reply.c
Merge branch 'master' into dev-master
[mirror_frr.git] / eigrpd / eigrp_reply.c
1 /*
2 * EIGRP Sending and Receiving EIGRP Reply Packets.
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 *
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
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"
61 #include "eigrpd/eigrp_memory.h"
62
63 void eigrp_send_reply(struct eigrp_neighbor *nbr, struct eigrp_prefix_entry *pe)
64 {
65 struct eigrp_packet *ep;
66 u_int16_t length = EIGRP_HEADER_LEN;
67
68 struct access_list *alist;
69 struct prefix_list *plist;
70 struct access_list *alist_i;
71 struct prefix_list *plist_i;
72 struct eigrp *e;
73 struct eigrp_prefix_entry *pe2;
74
75 // TODO: Work in progress
76 /* Filtering */
77 /* get list from eigrp process */
78 e = eigrp_lookup();
79 pe2 = XCALLOC(MTYPE_EIGRP_PREFIX_ENTRY,
80 sizeof(struct eigrp_prefix_entry));
81 memcpy(pe2, pe, sizeof(struct eigrp_prefix_entry));
82 /* Get access-lists and prefix-lists from process and interface */
83 alist = e->list[EIGRP_FILTER_OUT];
84 plist = e->prefix[EIGRP_FILTER_OUT];
85 alist_i = nbr->ei->list[EIGRP_FILTER_OUT];
86 plist_i = nbr->ei->prefix[EIGRP_FILTER_OUT];
87
88 /* Check if any list fits */
89 if ((alist
90 && access_list_apply(alist, pe2->destination)
91 == FILTER_DENY)
92 || (plist
93 && prefix_list_apply(plist,
94 pe2->destination)
95 == PREFIX_DENY)
96 || (alist_i
97 && access_list_apply(alist_i,
98 pe2->destination)
99 == FILTER_DENY)
100 || (plist_i
101 && prefix_list_apply(plist_i,
102 pe2->destination)
103 == PREFIX_DENY)) {
104 zlog_info("REPLY SEND: Setting Metric to max");
105 pe2->reported_metric.delay = EIGRP_MAX_METRIC;
106
107 }
108
109 /*
110 * End of filtering
111 */
112
113 ep = eigrp_packet_new(nbr->ei->ifp->mtu, nbr);
114
115 /* Prepare EIGRP INIT UPDATE header */
116 eigrp_packet_header_init(EIGRP_OPC_REPLY, e, ep->s, 0,
117 nbr->ei->eigrp->sequence_number, 0);
118
119 // encode Authentication TLV, if needed
120 if ((IF_DEF_PARAMS(nbr->ei->ifp)->auth_type == EIGRP_AUTH_TYPE_MD5)
121 && (IF_DEF_PARAMS(nbr->ei->ifp)->auth_keychain != NULL)) {
122 length += eigrp_add_authTLV_MD5_to_stream(ep->s, nbr->ei);
123 }
124
125
126 length += eigrp_add_internalTLV_to_stream(ep->s, pe2);
127
128 if ((IF_DEF_PARAMS(nbr->ei->ifp)->auth_type == EIGRP_AUTH_TYPE_MD5)
129 && (IF_DEF_PARAMS(nbr->ei->ifp)->auth_keychain != NULL)) {
130 eigrp_make_md5_digest(nbr->ei, ep->s, EIGRP_AUTH_UPDATE_FLAG);
131 }
132
133 /* EIGRP Checksum */
134 eigrp_packet_checksum(nbr->ei, ep->s, length);
135
136 ep->length = length;
137 ep->dst.s_addr = nbr->src.s_addr;
138
139 /*This ack number we await from neighbor*/
140 ep->sequence_number = nbr->ei->eigrp->sequence_number;
141
142 /*Put packet to retransmission queue*/
143 eigrp_fifo_push(nbr->retrans_queue, ep);
144
145 if (nbr->retrans_queue->count == 1) {
146 eigrp_send_packet_reliably(nbr);
147 }
148
149 XFREE(MTYPE_EIGRP_PREFIX_ENTRY, pe2);
150 }
151
152 /*EIGRP REPLY read function*/
153 void eigrp_reply_receive(struct eigrp *eigrp, struct ip *iph,
154 struct eigrp_header *eigrph, struct stream *s,
155 struct eigrp_interface *ei, int size)
156 {
157 struct eigrp_neighbor *nbr;
158 struct TLV_IPv4_Internal_type *tlv;
159
160 struct access_list *alist;
161 struct prefix_list *plist;
162 struct access_list *alist_i;
163 struct prefix_list *plist_i;
164 struct eigrp *e;
165
166 u_int16_t type;
167
168 /* increment statistics. */
169 ei->reply_in++;
170
171 /* get neighbor struct */
172 nbr = eigrp_nbr_get(ei, eigrph, iph);
173
174 /* neighbor must be valid, eigrp_nbr_get creates if none existed */
175 assert(nbr);
176
177 nbr->recv_sequence_number = ntohl(eigrph->sequence);
178
179 while (s->endp > s->getp) {
180 type = stream_getw(s);
181 if (type == EIGRP_TLV_IPv4_INT) {
182 struct prefix dest_addr;
183
184 stream_set_getp(s, s->getp - sizeof(u_int16_t));
185
186 tlv = eigrp_read_ipv4_tlv(s);
187
188 dest_addr.family = AF_INET;
189 dest_addr.u.prefix4 = tlv->destination;
190 dest_addr.prefixlen = tlv->prefix_length;
191 struct eigrp_prefix_entry *dest =
192 eigrp_topology_table_lookup_ipv4(
193 eigrp->topology_table, &dest_addr);
194 /*
195 * Destination must exists
196 */
197 assert(dest);
198
199 struct eigrp_fsm_action_message msg;
200 struct eigrp_neighbor_entry *entry =
201 eigrp_prefix_entry_lookup(dest->entries, nbr);
202
203 /*
204 * Filtering
205 */
206 // TODO: Work in progress
207 /* get list from eigrp process */
208 e = eigrp_lookup();
209 /* Get access-lists and prefix-lists from process and
210 * interface */
211 alist = e->list[EIGRP_FILTER_IN];
212 plist = e->prefix[EIGRP_FILTER_IN];
213 alist_i = ei->list[EIGRP_FILTER_IN];
214 plist_i = ei->prefix[EIGRP_FILTER_IN];
215 /* Check if any list fits */
216 if ((alist
217 && access_list_apply(alist,
218 (struct prefix *)&dest_addr)
219 == FILTER_DENY)
220 || (plist
221 && prefix_list_apply(
222 plist, (struct prefix *)&dest_addr)
223 == PREFIX_DENY)
224 || (alist_i
225 && access_list_apply(
226 alist_i, (struct prefix *)&dest_addr)
227 == FILTER_DENY)
228 || (plist_i
229 && prefix_list_apply(
230 plist_i, (struct prefix *)&dest_addr)
231 == PREFIX_DENY)) {
232 tlv->metric.delay = EIGRP_MAX_METRIC;
233 }
234 /*
235 * End of filtering
236 */
237
238 msg.packet_type = EIGRP_OPC_REPLY;
239 msg.eigrp = eigrp;
240 msg.data_type = EIGRP_INT;
241 msg.adv_router = nbr;
242 msg.metrics = tlv->metric;
243 msg.entry = entry;
244 msg.prefix = dest;
245 eigrp_fsm_event(&msg);
246
247
248 eigrp_IPv4_InternalTLV_free(tlv);
249 }
250 }
251 eigrp_hello_send_ack(nbr);
252 }