]> git.proxmox.com Git - mirror_frr.git/blob - eigrpd/eigrp_reply.c
Merge branch 'master' into docuser
[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 struct eigrp_interface *ei = nbr->ei;
68 struct eigrp *eigrp = ei->eigrp;
69 struct eigrp_prefix_entry *pe2;
70
71 // TODO: Work in progress
72 /* Filtering */
73 /* get list from eigrp process */
74 pe2 = XCALLOC(MTYPE_EIGRP_PREFIX_ENTRY,
75 sizeof(struct eigrp_prefix_entry));
76 memcpy(pe2, pe, sizeof(struct eigrp_prefix_entry));
77
78 if (eigrp_update_prefix_apply(eigrp, ei, EIGRP_FILTER_OUT,
79 pe2->destination)) {
80 zlog_info("REPLY SEND: Setting Metric to max");
81 pe2->reported_metric.delay = EIGRP_MAX_METRIC;
82 }
83
84 /*
85 * End of filtering
86 */
87
88 ep = eigrp_packet_new(ei->ifp->mtu, nbr);
89
90 /* Prepare EIGRP INIT UPDATE header */
91 eigrp_packet_header_init(EIGRP_OPC_REPLY, eigrp, ep->s, 0,
92 eigrp->sequence_number, 0);
93
94 // encode Authentication TLV, if needed
95 if (ei->params.auth_type == EIGRP_AUTH_TYPE_MD5
96 && (ei->params.auth_keychain != NULL)) {
97 length += eigrp_add_authTLV_MD5_to_stream(ep->s, ei);
98 }
99
100
101 length += eigrp_add_internalTLV_to_stream(ep->s, pe2);
102
103 if ((ei->params.auth_type == EIGRP_AUTH_TYPE_MD5)
104 && (ei->params.auth_keychain != NULL)) {
105 eigrp_make_md5_digest(ei, ep->s, EIGRP_AUTH_UPDATE_FLAG);
106 }
107
108 /* EIGRP Checksum */
109 eigrp_packet_checksum(ei, ep->s, length);
110
111 ep->length = length;
112 ep->dst.s_addr = nbr->src.s_addr;
113
114 /*This ack number we await from neighbor*/
115 ep->sequence_number = eigrp->sequence_number;
116
117 /*Put packet to retransmission queue*/
118 eigrp_fifo_push(nbr->retrans_queue, ep);
119
120 if (nbr->retrans_queue->count == 1) {
121 eigrp_send_packet_reliably(nbr);
122 }
123
124 XFREE(MTYPE_EIGRP_PREFIX_ENTRY, pe2);
125 }
126
127 /*EIGRP REPLY read function*/
128 void eigrp_reply_receive(struct eigrp *eigrp, struct ip *iph,
129 struct eigrp_header *eigrph, struct stream *s,
130 struct eigrp_interface *ei, int size)
131 {
132 struct eigrp_neighbor *nbr;
133 struct TLV_IPv4_Internal_type *tlv;
134
135 u_int16_t type;
136
137 /* increment statistics. */
138 ei->reply_in++;
139
140 /* get neighbor struct */
141 nbr = eigrp_nbr_get(ei, eigrph, iph);
142
143 /* neighbor must be valid, eigrp_nbr_get creates if none existed */
144 assert(nbr);
145
146 nbr->recv_sequence_number = ntohl(eigrph->sequence);
147
148 while (s->endp > s->getp) {
149 type = stream_getw(s);
150
151 if (type != EIGRP_TLV_IPv4_INT)
152 continue;
153
154 struct prefix dest_addr;
155
156 stream_set_getp(s, s->getp - sizeof(u_int16_t));
157
158 tlv = eigrp_read_ipv4_tlv(s);
159
160 dest_addr.family = AF_INET;
161 dest_addr.u.prefix4 = tlv->destination;
162 dest_addr.prefixlen = tlv->prefix_length;
163 struct eigrp_prefix_entry *dest =
164 eigrp_topology_table_lookup_ipv4(eigrp->topology_table,
165 &dest_addr);
166 /*
167 * Destination must exists
168 */
169 if (!dest) {
170 char buf[PREFIX_STRLEN];
171
172 zlog_err(
173 "%s: Received prefix %s which we do not know about",
174 __PRETTY_FUNCTION__,
175 prefix2str(&dest_addr, buf, sizeof(buf)));
176 eigrp_IPv4_InternalTLV_free(tlv);
177 continue;
178 }
179
180 struct eigrp_fsm_action_message msg;
181 struct eigrp_nexthop_entry *entry =
182 eigrp_prefix_entry_lookup(dest->entries, nbr);
183
184 if (eigrp_update_prefix_apply(eigrp, ei, EIGRP_FILTER_IN,
185 &dest_addr)) {
186 tlv->metric.delay = EIGRP_MAX_METRIC;
187 }
188 /*
189 * End of filtering
190 */
191
192 msg.packet_type = EIGRP_OPC_REPLY;
193 msg.eigrp = eigrp;
194 msg.data_type = EIGRP_INT;
195 msg.adv_router = nbr;
196 msg.metrics = tlv->metric;
197 msg.entry = entry;
198 msg.prefix = dest;
199 eigrp_fsm_event(&msg);
200
201 eigrp_IPv4_InternalTLV_free(tlv);
202 }
203 eigrp_hello_send_ack(nbr);
204 }