2 * EIGRP Sending and Receiving EIGRP 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
24 * along with GNU Zebra; see the file COPYING. If not, write to the Free
25 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
37 #include "sockunion.h"
45 #include "eigrpd/eigrp_structs.h"
46 #include "eigrpd/eigrpd.h"
47 #include "eigrpd/eigrp_interface.h"
48 #include "eigrpd/eigrp_neighbor.h"
49 #include "eigrpd/eigrp_packet.h"
50 #include "eigrpd/eigrp_zebra.h"
51 #include "eigrpd/eigrp_vty.h"
52 #include "eigrpd/eigrp_dump.h"
53 #include "eigrpd/eigrp_macros.h"
54 #include "eigrpd/eigrp_topology.h"
55 #include "eigrpd/eigrp_fsm.h"
56 #include "eigrpd/eigrp_memory.h"
59 eigrp_query_send_all (struct eigrp
*eigrp
)
61 struct eigrp_interface
*iface
;
62 struct listnode
*node
, *node2
, *nnode2
;
63 struct eigrp_prefix_entry
*pe
;
68 zlog_debug("EIGRP Routing Process not enabled");
73 for (ALL_LIST_ELEMENTS_RO(eigrp
->eiflist
, node
, iface
))
75 eigrp_send_query(iface
);
79 for (ALL_LIST_ELEMENTS(eigrp
->topology_changes_internalIPV4
, node2
, nnode2
, pe
))
81 if(pe
->req_action
& EIGRP_FSM_NEED_QUERY
)
83 pe
->req_action
&= ~EIGRP_FSM_NEED_QUERY
;
84 listnode_delete(eigrp
->topology_changes_internalIPV4
, pe
);
91 /*EIGRP QUERY read function*/
93 eigrp_query_receive (struct eigrp
*eigrp
, struct ip
*iph
, struct eigrp_header
*eigrph
,
94 struct stream
* s
, struct eigrp_interface
*ei
, int size
)
96 struct eigrp_neighbor
*nbr
;
97 struct TLV_IPv4_Internal_type
*tlv
;
101 /* increment statistics. */
104 /* get neighbor struct */
105 nbr
= eigrp_nbr_get(ei
, eigrph
, iph
);
107 /* neighbor must be valid, eigrp_nbr_get creates if none existed */
110 nbr
->recv_sequence_number
= ntohl(eigrph
->sequence
);
112 while (s
->endp
> s
->getp
)
114 type
= stream_getw(s
);
115 if (type
== EIGRP_TLV_IPv4_INT
)
117 stream_set_getp(s
, s
->getp
- sizeof(u_int16_t
));
119 tlv
= eigrp_read_ipv4_tlv(s
);
121 struct prefix_ipv4
*dest_addr
;
122 dest_addr
= prefix_ipv4_new();
123 dest_addr
->prefix
= tlv
->destination
;
124 dest_addr
->prefixlen
= tlv
->prefix_length
;
125 struct eigrp_prefix_entry
*dest
=
126 eigrp_topology_table_lookup_ipv4(eigrp
->topology_table
, dest_addr
);
128 /* If the destination exists (it should, but one never know)*/
131 struct eigrp_fsm_action_message
*msg
;
132 msg
= XCALLOC(MTYPE_EIGRP_FSM_MSG
,
133 sizeof(struct eigrp_fsm_action_message
));
134 struct eigrp_neighbor_entry
*entry
=
135 eigrp_prefix_entry_lookup(dest
->entries
, nbr
);
136 msg
->packet_type
= EIGRP_OPC_QUERY
;
138 msg
->data_type
= EIGRP_TLV_IPv4_INT
;
139 msg
->adv_router
= nbr
;
140 msg
->data
.ipv4_int_type
= tlv
;
143 int event
= eigrp_get_fsm_event(msg
);
144 eigrp_fsm_event(msg
, event
);
146 eigrp_IPv4_InternalTLV_free (tlv
);
149 eigrp_hello_send_ack(nbr
);
150 eigrp_query_send_all(eigrp
);
151 eigrp_update_send_all(eigrp
,nbr
->ei
);
155 eigrp_send_query (struct eigrp_interface
*ei
)
157 struct eigrp_packet
*ep
;
158 u_int16_t length
= EIGRP_HEADER_LEN
;
159 struct listnode
*node
, *nnode
, *node2
, *nnode2
;
160 struct eigrp_neighbor
*nbr
;
161 struct eigrp_prefix_entry
*pe
;
164 ep
= eigrp_packet_new(ei
->ifp
->mtu
);
166 /* Prepare EIGRP INIT UPDATE header */
167 eigrp_packet_header_init(EIGRP_OPC_QUERY
, ei
, ep
->s
, 0,
168 ei
->eigrp
->sequence_number
, 0);
170 // encode Authentication TLV, if needed
171 if((IF_DEF_PARAMS (ei
->ifp
)->auth_type
== EIGRP_AUTH_TYPE_MD5
) &&
172 (IF_DEF_PARAMS (ei
->ifp
)->auth_keychain
!= NULL
))
174 length
+= eigrp_add_authTLV_MD5_to_stream(ep
->s
,ei
);
178 for (ALL_LIST_ELEMENTS(ei
->eigrp
->topology_changes_internalIPV4
, node
, nnode
, pe
))
180 if(pe
->req_action
& EIGRP_FSM_NEED_QUERY
)
182 length
+= eigrp_add_internalTLV_to_stream(ep
->s
, pe
);
183 for (ALL_LIST_ELEMENTS(ei
->nbrs
, node2
, nnode2
, nbr
))
185 if(nbr
->state
== EIGRP_NEIGHBOR_UP
)
187 listnode_add(pe
->rij
, nbr
);
196 eigrp_packet_free(ep
);
200 if((IF_DEF_PARAMS (ei
->ifp
)->auth_type
== EIGRP_AUTH_TYPE_MD5
) &&
201 (IF_DEF_PARAMS (ei
->ifp
)->auth_keychain
!= NULL
))
203 eigrp_make_md5_digest(ei
,ep
->s
, EIGRP_AUTH_UPDATE_FLAG
);
207 eigrp_packet_checksum(ei
, ep
->s
, length
);
210 ep
->dst
.s_addr
= htonl(EIGRP_MULTICAST_ADDRESS
);
212 /*This ack number we await from neighbor*/
213 ep
->sequence_number
= ei
->eigrp
->sequence_number
;
215 for (ALL_LIST_ELEMENTS(ei
->nbrs
, node2
, nnode2
, nbr
))
217 if (nbr
->state
== EIGRP_NEIGHBOR_UP
)
219 /*Put packet to retransmission queue*/
220 eigrp_fifo_push_head(nbr
->retrans_queue
, ep
);
222 if (nbr
->retrans_queue
->count
== 1)
224 eigrp_send_packet_reliably(nbr
);