]>
Commit | Line | Data |
---|---|---|
7f57883e DS |
1 | /* |
2 | * EIGRP Sending and Receiving EIGRP SIA-Reply 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 | 26 | */ |
7f57883e DS |
27 | #include <zebra.h> |
28 | ||
29 | #include "thread.h" | |
30 | #include "memory.h" | |
31 | #include "linklist.h" | |
32 | #include "prefix.h" | |
33 | #include "if.h" | |
34 | #include "table.h" | |
35 | #include "sockunion.h" | |
36 | #include "stream.h" | |
37 | #include "log.h" | |
38 | #include "sockopt.h" | |
39 | #include "checksum.h" | |
40 | #include "md5.h" | |
41 | #include "vty.h" | |
42 | ||
43 | #include "eigrpd/eigrp_structs.h" | |
44 | #include "eigrpd/eigrpd.h" | |
45 | #include "eigrpd/eigrp_interface.h" | |
46 | #include "eigrpd/eigrp_neighbor.h" | |
47 | #include "eigrpd/eigrp_packet.h" | |
48 | #include "eigrpd/eigrp_zebra.h" | |
49 | #include "eigrpd/eigrp_vty.h" | |
50 | #include "eigrpd/eigrp_dump.h" | |
51 | #include "eigrpd/eigrp_macros.h" | |
52 | #include "eigrpd/eigrp_topology.h" | |
53 | #include "eigrpd/eigrp_fsm.h" | |
54 | #include "eigrpd/eigrp_memory.h" | |
55 | ||
56 | /*EIGRP SIA-REPLY read function*/ | |
57 | void | |
58 | eigrp_siareply_receive (struct eigrp *eigrp, struct ip *iph, struct eigrp_header *eigrph, | |
f9e5c9ca | 59 | struct stream * s, struct eigrp_interface *ei, int size) |
7f57883e DS |
60 | { |
61 | struct eigrp_neighbor *nbr; | |
62 | struct TLV_IPv4_Internal_type *tlv; | |
63 | ||
64 | u_int16_t type; | |
65 | ||
66 | /* increment statistics. */ | |
67 | ei->siaReply_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 | { | |
79 | type = stream_getw(s); | |
80 | if (type == EIGRP_TLV_IPv4_INT) | |
81 | { | |
057fad8d DS |
82 | struct prefix_ipv4 dest_addr; |
83 | ||
7f57883e DS |
84 | stream_set_getp(s, s->getp - sizeof(u_int16_t)); |
85 | ||
86 | tlv = eigrp_read_ipv4_tlv(s); | |
87 | ||
057fad8d DS |
88 | dest_addr.family = AFI_IP; |
89 | dest_addr.prefix = tlv->destination; | |
90 | dest_addr.prefixlen = tlv->prefix_length; | |
f9e5c9ca | 91 | struct eigrp_prefix_entry *dest = |
057fad8d | 92 | eigrp_topology_table_lookup_ipv4(eigrp->topology_table, &dest_addr); |
7f57883e DS |
93 | |
94 | /* If the destination exists (it should, but one never know)*/ | |
95 | if (dest != NULL) | |
96 | { | |
97 | struct eigrp_fsm_action_message *msg; | |
98 | msg = XCALLOC(MTYPE_EIGRP_FSM_MSG, | |
f9e5c9ca DS |
99 | sizeof(struct eigrp_fsm_action_message)); |
100 | struct eigrp_neighbor_entry *entry = | |
101 | eigrp_prefix_entry_lookup(dest->entries, nbr); | |
7f57883e DS |
102 | msg->packet_type = EIGRP_OPC_SIAQUERY; |
103 | msg->eigrp = eigrp; | |
104 | msg->data_type = EIGRP_TLV_IPv4_INT; | |
105 | msg->adv_router = nbr; | |
106 | msg->data.ipv4_int_type = tlv; | |
107 | msg->entry = entry; | |
108 | msg->prefix = dest; | |
109 | int event = eigrp_get_fsm_event(msg); | |
110 | eigrp_fsm_event(msg, event); | |
111 | } | |
112 | eigrp_IPv4_InternalTLV_free (tlv); | |
113 | } | |
114 | } | |
115 | eigrp_hello_send_ack(nbr); | |
116 | } | |
117 | ||
118 | void | |
119 | eigrp_send_siareply (struct eigrp_neighbor *nbr, struct eigrp_prefix_entry *pe) | |
120 | { | |
121 | struct eigrp_packet *ep; | |
122 | u_int16_t length = EIGRP_HEADER_LEN; | |
123 | ||
124 | ep = eigrp_packet_new(nbr->ei->ifp->mtu); | |
125 | ||
126 | /* Prepare EIGRP INIT UPDATE header */ | |
127 | eigrp_packet_header_init(EIGRP_OPC_SIAREPLY, nbr->ei, ep->s, 0, | |
f9e5c9ca | 128 | nbr->ei->eigrp->sequence_number, 0); |
7f57883e DS |
129 | |
130 | // encode Authentication TLV, if needed | |
f9e5c9ca DS |
131 | if((IF_DEF_PARAMS (nbr->ei->ifp)->auth_type == EIGRP_AUTH_TYPE_MD5) && |
132 | (IF_DEF_PARAMS (nbr->ei->ifp)->auth_keychain != NULL)) | |
7f57883e DS |
133 | { |
134 | length += eigrp_add_authTLV_MD5_to_stream(ep->s,nbr->ei); | |
135 | } | |
136 | ||
f9e5c9ca | 137 | length += eigrp_add_internalTLV_to_stream(ep->s, pe); |
7f57883e | 138 | |
f9e5c9ca DS |
139 | if((IF_DEF_PARAMS (nbr->ei->ifp)->auth_type == EIGRP_AUTH_TYPE_MD5) && |
140 | (IF_DEF_PARAMS (nbr->ei->ifp)->auth_keychain != NULL)) | |
7f57883e DS |
141 | { |
142 | eigrp_make_md5_digest(nbr->ei,ep->s, EIGRP_AUTH_UPDATE_FLAG); | |
143 | } | |
144 | ||
145 | /* EIGRP Checksum */ | |
f9e5c9ca | 146 | eigrp_packet_checksum(nbr->ei, ep->s, length); |
7f57883e | 147 | |
f9e5c9ca DS |
148 | ep->length = length; |
149 | ep->dst.s_addr = nbr->src.s_addr; | |
7f57883e | 150 | |
f9e5c9ca DS |
151 | /*This ack number we await from neighbor*/ |
152 | ep->sequence_number = nbr->ei->eigrp->sequence_number; | |
7f57883e | 153 | |
f9e5c9ca DS |
154 | if (nbr->state == EIGRP_NEIGHBOR_UP) |
155 | { | |
156 | /*Put packet to retransmission queue*/ | |
157 | eigrp_fifo_push_head(nbr->retrans_queue, ep); | |
7f57883e | 158 | |
f9e5c9ca DS |
159 | if (nbr->retrans_queue->count == 1) |
160 | { | |
161 | eigrp_send_packet_reliably(nbr); | |
162 | } | |
163 | } | |
057fad8d DS |
164 | else |
165 | eigrp_packet_free(ep); | |
7f57883e DS |
166 | } |
167 | ||
168 |