2 * Eigrp Sending and Receiving EIGRP Reply Packets.
3 * Copyright (C) 2013-2016
15 * This file is part of GNU Zebra.
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
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.
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
40 #include "sockunion.h"
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 #include "eigrpd/eigrp_errors.h"
64 void eigrp_send_reply(struct eigrp_neighbor
*nbr
, struct eigrp_prefix_entry
*pe
)
66 struct eigrp_packet
*ep
;
67 uint16_t length
= EIGRP_HEADER_LEN
;
68 struct eigrp_interface
*ei
= nbr
->ei
;
69 struct eigrp
*eigrp
= ei
->eigrp
;
70 struct eigrp_prefix_entry
*pe2
;
72 // TODO: Work in progress
74 /* get list from eigrp process */
75 pe2
= XCALLOC(MTYPE_EIGRP_PREFIX_ENTRY
,
76 sizeof(struct eigrp_prefix_entry
));
77 memcpy(pe2
, pe
, sizeof(struct eigrp_prefix_entry
));
79 if (eigrp_update_prefix_apply(eigrp
, ei
, EIGRP_FILTER_OUT
,
81 zlog_info("REPLY SEND: Setting Metric to max");
82 pe2
->reported_metric
.delay
= EIGRP_MAX_METRIC
;
89 ep
= eigrp_packet_new(EIGRP_PACKET_MTU(ei
->ifp
->mtu
), nbr
);
91 /* Prepare EIGRP INIT UPDATE header */
92 eigrp_packet_header_init(EIGRP_OPC_REPLY
, eigrp
, ep
->s
, 0,
93 eigrp
->sequence_number
, 0);
95 // encode Authentication TLV, if needed
96 if (ei
->params
.auth_type
== EIGRP_AUTH_TYPE_MD5
97 && (ei
->params
.auth_keychain
!= NULL
)) {
98 length
+= eigrp_add_authTLV_MD5_to_stream(ep
->s
, ei
);
102 length
+= eigrp_add_internalTLV_to_stream(ep
->s
, pe2
);
104 if ((ei
->params
.auth_type
== EIGRP_AUTH_TYPE_MD5
)
105 && (ei
->params
.auth_keychain
!= NULL
)) {
106 eigrp_make_md5_digest(ei
, ep
->s
, EIGRP_AUTH_UPDATE_FLAG
);
110 eigrp_packet_checksum(ei
, ep
->s
, length
);
113 ep
->dst
.s_addr
= nbr
->src
.s_addr
;
115 /*This ack number we await from neighbor*/
116 ep
->sequence_number
= eigrp
->sequence_number
;
118 /*Put packet to retransmission queue*/
119 eigrp_fifo_push(nbr
->retrans_queue
, ep
);
121 if (nbr
->retrans_queue
->count
== 1) {
122 eigrp_send_packet_reliably(nbr
);
125 XFREE(MTYPE_EIGRP_PREFIX_ENTRY
, pe2
);
128 /*EIGRP REPLY read function*/
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
)
133 struct eigrp_neighbor
*nbr
;
134 struct TLV_IPv4_Internal_type
*tlv
;
138 /* increment statistics. */
141 /* get neighbor struct */
142 nbr
= eigrp_nbr_get(ei
, eigrph
, iph
);
144 /* neighbor must be valid, eigrp_nbr_get creates if none existed */
147 nbr
->recv_sequence_number
= ntohl(eigrph
->sequence
);
149 while (s
->endp
> s
->getp
) {
150 type
= stream_getw(s
);
152 if (type
!= EIGRP_TLV_IPv4_INT
)
155 struct prefix dest_addr
;
157 stream_set_getp(s
, s
->getp
- sizeof(uint16_t));
159 tlv
= eigrp_read_ipv4_tlv(s
);
161 dest_addr
.family
= AF_INET
;
162 dest_addr
.u
.prefix4
= tlv
->destination
;
163 dest_addr
.prefixlen
= tlv
->prefix_length
;
164 struct eigrp_prefix_entry
*dest
=
165 eigrp_topology_table_lookup_ipv4(eigrp
->topology_table
,
168 * Destination must exists
171 char buf
[PREFIX_STRLEN
];
175 "%s: Received prefix %s which we do not know about",
177 prefix2str(&dest_addr
, buf
, sizeof(buf
)));
178 eigrp_IPv4_InternalTLV_free(tlv
);
182 struct eigrp_fsm_action_message msg
;
183 struct eigrp_nexthop_entry
*entry
=
184 eigrp_prefix_entry_lookup(dest
->entries
, nbr
);
186 if (eigrp_update_prefix_apply(eigrp
, ei
, EIGRP_FILTER_IN
,
188 tlv
->metric
.delay
= EIGRP_MAX_METRIC
;
194 msg
.packet_type
= EIGRP_OPC_REPLY
;
196 msg
.data_type
= EIGRP_INT
;
197 msg
.adv_router
= nbr
;
198 msg
.metrics
= tlv
->metric
;
201 eigrp_fsm_event(&msg
);
203 eigrp_IPv4_InternalTLV_free(tlv
);
205 eigrp_hello_send_ack(nbr
);