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