]>
Commit | Line | Data |
---|---|---|
7f57883e DS |
1 | /* |
2 | * EIGRP Sending and Receiving EIGRP SIA-Query Packets. | |
3 | * Copyright (C) 2013-2014 | |
4 | * Authors: | |
5 | * Donnie Savage | |
6 | * Jan Janovic | |
7 | * Matej Perina | |
8 | * Peter Orsag | |
9 | * Peter Paluch | |
10 | * | |
11 | * This file is part of GNU Zebra. | |
12 | * | |
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 | |
16 | * later version. | |
17 | * | |
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. | |
22 | * | |
896014f4 DL |
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 | |
7f57883e DS |
26 | */ |
27 | ||
28 | #include <zebra.h> | |
29 | ||
30 | #include "thread.h" | |
31 | #include "memory.h" | |
32 | #include "linklist.h" | |
33 | #include "prefix.h" | |
34 | #include "if.h" | |
35 | #include "table.h" | |
36 | #include "sockunion.h" | |
37 | #include "stream.h" | |
38 | #include "log.h" | |
39 | #include "sockopt.h" | |
40 | #include "checksum.h" | |
41 | #include "md5.h" | |
42 | #include "vty.h" | |
43 | ||
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" | |
7f57883e DS |
55 | |
56 | /*EIGRP SIA-QUERY read function*/ | |
d62a17ae | 57 | void eigrp_siaquery_receive(struct eigrp *eigrp, struct ip *iph, |
58 | struct eigrp_header *eigrph, struct stream *s, | |
59 | struct eigrp_interface *ei, int size) | |
7f57883e | 60 | { |
d62a17ae | 61 | struct eigrp_neighbor *nbr; |
62 | struct TLV_IPv4_Internal_type *tlv; | |
63 | ||
d7c0a89a | 64 | uint16_t type; |
d62a17ae | 65 | |
66 | /* increment statistics. */ | |
67 | ei->siaQuery_in++; | |
68 | ||
69 | /* get neighbor struct */ | |
70 | nbr = eigrp_nbr_get(ei, eigrph, iph); | |
71 | ||
72 | /* neighbor must be valid, eigrp_nbr_get creates if none existed */ | |
73 | assert(nbr); | |
74 | ||
75 | nbr->recv_sequence_number = ntohl(eigrph->sequence); | |
76 | ||
77 | while (s->endp > s->getp) { | |
78 | type = stream_getw(s); | |
79 | if (type == EIGRP_TLV_IPv4_INT) { | |
476a1469 | 80 | struct prefix dest_addr; |
d62a17ae | 81 | |
d7c0a89a | 82 | stream_set_getp(s, s->getp - sizeof(uint16_t)); |
d62a17ae | 83 | |
84 | tlv = eigrp_read_ipv4_tlv(s); | |
85 | ||
86 | dest_addr.family = AFI_IP; | |
476a1469 | 87 | dest_addr.u.prefix4 = tlv->destination; |
d62a17ae | 88 | dest_addr.prefixlen = tlv->prefix_length; |
dc4accdd | 89 | struct eigrp_prefix_descriptor *dest = |
d62a17ae | 90 | eigrp_topology_table_lookup_ipv4( |
91 | eigrp->topology_table, &dest_addr); | |
92 | ||
93 | /* If the destination exists (it should, but one never | |
94 | * know)*/ | |
95 | if (dest != NULL) { | |
92035b1d | 96 | struct eigrp_fsm_action_message msg; |
dc4accdd DS |
97 | struct eigrp_route_descriptor *entry = |
98 | eigrp_route_descriptor_lookup( | |
99 | dest->entries, nbr); | |
92035b1d DS |
100 | msg.packet_type = EIGRP_OPC_SIAQUERY; |
101 | msg.eigrp = eigrp; | |
7cfa4322 | 102 | msg.data_type = EIGRP_INT; |
92035b1d | 103 | msg.adv_router = nbr; |
db6ec9ff | 104 | msg.metrics = tlv->metric; |
92035b1d DS |
105 | msg.entry = entry; |
106 | msg.prefix = dest; | |
6118272f | 107 | eigrp_fsm_event(&msg); |
d62a17ae | 108 | } |
109 | eigrp_IPv4_InternalTLV_free(tlv); | |
110 | } | |
111 | } | |
112 | eigrp_hello_send_ack(nbr); | |
7f57883e DS |
113 | } |
114 | ||
d62a17ae | 115 | void eigrp_send_siaquery(struct eigrp_neighbor *nbr, |
dc4accdd | 116 | struct eigrp_prefix_descriptor *pe) |
7f57883e | 117 | { |
d62a17ae | 118 | struct eigrp_packet *ep; |
d7c0a89a | 119 | uint16_t length = EIGRP_HEADER_LEN; |
d62a17ae | 120 | |
9378632f | 121 | ep = eigrp_packet_new(EIGRP_PACKET_MTU(nbr->ei->ifp->mtu), nbr); |
d62a17ae | 122 | |
123 | /* Prepare EIGRP INIT UPDATE header */ | |
cf2f4dae | 124 | eigrp_packet_header_init(EIGRP_OPC_SIAQUERY, nbr->ei->eigrp, ep->s, 0, |
d62a17ae | 125 | nbr->ei->eigrp->sequence_number, 0); |
126 | ||
127 | // encode Authentication TLV, if needed | |
b748db67 DS |
128 | if ((nbr->ei->params.auth_type == EIGRP_AUTH_TYPE_MD5) |
129 | && (nbr->ei->params.auth_keychain != NULL)) { | |
d62a17ae | 130 | length += eigrp_add_authTLV_MD5_to_stream(ep->s, nbr->ei); |
131 | } | |
132 | ||
133 | length += eigrp_add_internalTLV_to_stream(ep->s, pe); | |
134 | ||
b748db67 DS |
135 | if ((nbr->ei->params.auth_type == EIGRP_AUTH_TYPE_MD5) |
136 | && (nbr->ei->params.auth_keychain != NULL)) { | |
d62a17ae | 137 | eigrp_make_md5_digest(nbr->ei, ep->s, EIGRP_AUTH_UPDATE_FLAG); |
138 | } | |
139 | ||
140 | /* EIGRP Checksum */ | |
141 | eigrp_packet_checksum(nbr->ei, ep->s, length); | |
142 | ||
143 | ep->length = length; | |
144 | ep->dst.s_addr = nbr->src.s_addr; | |
145 | ||
146 | /*This ack number we await from neighbor*/ | |
147 | ep->sequence_number = nbr->ei->eigrp->sequence_number; | |
148 | ||
149 | if (nbr->state == EIGRP_NEIGHBOR_UP) { | |
150 | /*Put packet to retransmission queue*/ | |
f90f65a2 | 151 | eigrp_fifo_push(nbr->retrans_queue, ep); |
d62a17ae | 152 | |
153 | if (nbr->retrans_queue->count == 1) { | |
154 | eigrp_send_packet_reliably(nbr); | |
155 | } | |
156 | } else | |
157 | eigrp_packet_free(ep); | |
7f57883e | 158 | } |