]> git.proxmox.com Git - mirror_frr.git/blame - eigrpd/eigrp_siareply.c
tools: improve explanation of 'wrap' options
[mirror_frr.git] / eigrpd / eigrp_siareply.c
CommitLineData
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"
7f57883e
DS
54
55/*EIGRP SIA-REPLY read function*/
d62a17ae 56void eigrp_siareply_receive(struct eigrp *eigrp, struct ip *iph,
57 struct eigrp_header *eigrph, struct stream *s,
58 struct eigrp_interface *ei, int size)
7f57883e 59{
d62a17ae 60 struct eigrp_neighbor *nbr;
61 struct TLV_IPv4_Internal_type *tlv;
62
d7c0a89a 63 uint16_t type;
d62a17ae 64
65 /* increment statistics. */
66 ei->siaReply_in++;
67
68 /* get neighbor struct */
69 nbr = eigrp_nbr_get(ei, eigrph, iph);
70
71 /* neighbor must be valid, eigrp_nbr_get creates if none existed */
72 assert(nbr);
73
74 nbr->recv_sequence_number = ntohl(eigrph->sequence);
75
76 while (s->endp > s->getp) {
77 type = stream_getw(s);
78 if (type == EIGRP_TLV_IPv4_INT) {
476a1469 79 struct prefix dest_addr;
d62a17ae 80
d7c0a89a 81 stream_set_getp(s, s->getp - sizeof(uint16_t));
d62a17ae 82
83 tlv = eigrp_read_ipv4_tlv(s);
84
85 dest_addr.family = AFI_IP;
476a1469 86 dest_addr.u.prefix4 = tlv->destination;
d62a17ae 87 dest_addr.prefixlen = tlv->prefix_length;
dc4accdd 88 struct eigrp_prefix_descriptor *dest =
d62a17ae 89 eigrp_topology_table_lookup_ipv4(
90 eigrp->topology_table, &dest_addr);
91
92 /* If the destination exists (it should, but one never
93 * know)*/
94 if (dest != NULL) {
92035b1d 95 struct eigrp_fsm_action_message msg;
dc4accdd
DS
96 struct eigrp_route_descriptor *entry =
97 eigrp_route_descriptor_lookup(
98 dest->entries, nbr);
92035b1d
DS
99 msg.packet_type = EIGRP_OPC_SIAQUERY;
100 msg.eigrp = eigrp;
7cfa4322 101 msg.data_type = EIGRP_INT;
92035b1d 102 msg.adv_router = nbr;
db6ec9ff 103 msg.metrics = tlv->metric;
92035b1d
DS
104 msg.entry = entry;
105 msg.prefix = dest;
6118272f 106 eigrp_fsm_event(&msg);
d62a17ae 107 }
108 eigrp_IPv4_InternalTLV_free(tlv);
109 }
110 }
111 eigrp_hello_send_ack(nbr);
7f57883e
DS
112}
113
d62a17ae 114void eigrp_send_siareply(struct eigrp_neighbor *nbr,
dc4accdd 115 struct eigrp_prefix_descriptor *pe)
7f57883e 116{
d62a17ae 117 struct eigrp_packet *ep;
d7c0a89a 118 uint16_t length = EIGRP_HEADER_LEN;
d62a17ae 119
9378632f 120 ep = eigrp_packet_new(EIGRP_PACKET_MTU(nbr->ei->ifp->mtu), nbr);
d62a17ae 121
122 /* Prepare EIGRP INIT UPDATE header */
cf2f4dae 123 eigrp_packet_header_init(EIGRP_OPC_SIAREPLY, nbr->ei->eigrp, ep->s, 0,
d62a17ae 124 nbr->ei->eigrp->sequence_number, 0);
125
126 // encode Authentication TLV, if needed
b748db67
DS
127 if (nbr->ei->params.auth_type == EIGRP_AUTH_TYPE_MD5
128 && nbr->ei->params.auth_keychain != NULL) {
d62a17ae 129 length += eigrp_add_authTLV_MD5_to_stream(ep->s, nbr->ei);
130 }
131
132 length += eigrp_add_internalTLV_to_stream(ep->s, pe);
7f57883e 133
b748db67
DS
134 if ((nbr->ei->params.auth_type == EIGRP_AUTH_TYPE_MD5)
135 && (nbr->ei->params.auth_keychain != NULL)) {
d62a17ae 136 eigrp_make_md5_digest(nbr->ei, ep->s, EIGRP_AUTH_UPDATE_FLAG);
137 }
7f57883e 138
d62a17ae 139 /* EIGRP Checksum */
140 eigrp_packet_checksum(nbr->ei, ep->s, length);
141
142 ep->length = length;
143 ep->dst.s_addr = nbr->src.s_addr;
144
145 /*This ack number we await from neighbor*/
146 ep->sequence_number = nbr->ei->eigrp->sequence_number;
147
148 if (nbr->state == EIGRP_NEIGHBOR_UP) {
149 /*Put packet to retransmission queue*/
f90f65a2 150 eigrp_fifo_push(nbr->retrans_queue, ep);
d62a17ae 151
152 if (nbr->retrans_queue->count == 1) {
153 eigrp_send_packet_reliably(nbr);
154 }
155 } else
156 eigrp_packet_free(ep);
157}