2 * EIGRP Sending and Receiving EIGRP SIA-Query Packets.
3 * Copyright (C) 2013-2014
11 * This file is part of GNU Zebra.
13 * GNU Zebra is free software; you can redistribute it and/or modify it
14 * under the terms of the GNU General Public License as published by the
15 * Free Software Foundation; either version 2, or (at your option) any
18 * GNU Zebra is distributed in the hope that it will be useful, but
19 * WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 * General Public License for more details.
23 * You should have received a copy of the GNU General Public License along
24 * with this program; see the file COPYING; if not, write to the Free Software
25 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
36 #include "sockunion.h"
44 #include "eigrpd/eigrp_structs.h"
45 #include "eigrpd/eigrpd.h"
46 #include "eigrpd/eigrp_interface.h"
47 #include "eigrpd/eigrp_neighbor.h"
48 #include "eigrpd/eigrp_packet.h"
49 #include "eigrpd/eigrp_zebra.h"
50 #include "eigrpd/eigrp_vty.h"
51 #include "eigrpd/eigrp_dump.h"
52 #include "eigrpd/eigrp_macros.h"
53 #include "eigrpd/eigrp_topology.h"
54 #include "eigrpd/eigrp_fsm.h"
55 #include "eigrpd/eigrp_memory.h"
57 /*EIGRP SIA-QUERY read function*/
58 void eigrp_siaquery_receive(struct eigrp
*eigrp
, struct ip
*iph
,
59 struct eigrp_header
*eigrph
, struct stream
*s
,
60 struct eigrp_interface
*ei
, int size
)
62 struct eigrp_neighbor
*nbr
;
63 struct TLV_IPv4_Internal_type
*tlv
;
67 /* increment statistics. */
70 /* get neighbor struct */
71 nbr
= eigrp_nbr_get(ei
, eigrph
, iph
);
73 /* neighbor must be valid, eigrp_nbr_get creates if none existed */
76 nbr
->recv_sequence_number
= ntohl(eigrph
->sequence
);
78 while (s
->endp
> s
->getp
) {
79 type
= stream_getw(s
);
80 if (type
== EIGRP_TLV_IPv4_INT
) {
81 struct prefix dest_addr
;
83 stream_set_getp(s
, s
->getp
- sizeof(uint16_t));
85 tlv
= eigrp_read_ipv4_tlv(s
);
87 dest_addr
.family
= AFI_IP
;
88 dest_addr
.u
.prefix4
= tlv
->destination
;
89 dest_addr
.prefixlen
= tlv
->prefix_length
;
90 struct eigrp_prefix_descriptor
*dest
=
91 eigrp_topology_table_lookup_ipv4(
92 eigrp
->topology_table
, &dest_addr
);
94 /* If the destination exists (it should, but one never
97 struct eigrp_fsm_action_message msg
;
98 struct eigrp_route_descriptor
*entry
=
99 eigrp_route_descriptor_lookup(
101 msg
.packet_type
= EIGRP_OPC_SIAQUERY
;
103 msg
.data_type
= EIGRP_INT
;
104 msg
.adv_router
= nbr
;
105 msg
.metrics
= tlv
->metric
;
108 eigrp_fsm_event(&msg
);
110 eigrp_IPv4_InternalTLV_free(tlv
);
113 eigrp_hello_send_ack(nbr
);
116 void eigrp_send_siaquery(struct eigrp_neighbor
*nbr
,
117 struct eigrp_prefix_descriptor
*pe
)
119 struct eigrp_packet
*ep
;
120 uint16_t length
= EIGRP_HEADER_LEN
;
122 ep
= eigrp_packet_new(EIGRP_PACKET_MTU(nbr
->ei
->ifp
->mtu
), nbr
);
124 /* Prepare EIGRP INIT UPDATE header */
125 eigrp_packet_header_init(EIGRP_OPC_SIAQUERY
, nbr
->ei
->eigrp
, ep
->s
, 0,
126 nbr
->ei
->eigrp
->sequence_number
, 0);
128 // encode Authentication TLV, if needed
129 if ((nbr
->ei
->params
.auth_type
== EIGRP_AUTH_TYPE_MD5
)
130 && (nbr
->ei
->params
.auth_keychain
!= NULL
)) {
131 length
+= eigrp_add_authTLV_MD5_to_stream(ep
->s
, nbr
->ei
);
134 length
+= eigrp_add_internalTLV_to_stream(ep
->s
, pe
);
136 if ((nbr
->ei
->params
.auth_type
== EIGRP_AUTH_TYPE_MD5
)
137 && (nbr
->ei
->params
.auth_keychain
!= NULL
)) {
138 eigrp_make_md5_digest(nbr
->ei
, ep
->s
, EIGRP_AUTH_UPDATE_FLAG
);
142 eigrp_packet_checksum(nbr
->ei
, ep
->s
, length
);
145 ep
->dst
.s_addr
= nbr
->src
.s_addr
;
147 /*This ack number we await from neighbor*/
148 ep
->sequence_number
= nbr
->ei
->eigrp
->sequence_number
;
150 if (nbr
->state
== EIGRP_NEIGHBOR_UP
) {
151 /*Put packet to retransmission queue*/
152 eigrp_fifo_push(nbr
->retrans_queue
, ep
);
154 if (nbr
->retrans_queue
->count
== 1) {
155 eigrp_send_packet_reliably(nbr
);
158 eigrp_packet_free(ep
);