]> git.proxmox.com Git - mirror_frr.git/blame - eigrpd/eigrp_siareply.c
eigrpd: Only install up to eigrp->max_paths into rib.
[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 *
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
26 * 02111-1307, USA.
27 */
28
29#include <zebra.h>
30
31#include "thread.h"
32#include "memory.h"
33#include "linklist.h"
34#include "prefix.h"
35#include "if.h"
36#include "table.h"
37#include "sockunion.h"
38#include "stream.h"
39#include "log.h"
40#include "sockopt.h"
41#include "checksum.h"
42#include "md5.h"
43#include "vty.h"
44
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"
57
58/*EIGRP SIA-REPLY read function*/
59void
60eigrp_siareply_receive (struct eigrp *eigrp, struct ip *iph, struct eigrp_header *eigrph,
61 struct stream * s, struct eigrp_interface *ei, int size)
62{
63 struct eigrp_neighbor *nbr;
64 struct TLV_IPv4_Internal_type *tlv;
65
66 u_int16_t type;
67
68 /* increment statistics. */
69 ei->siaReply_in++;
70
71 /* get neighbor struct */
72 nbr = eigrp_nbr_get(ei, eigrph, iph);
73
74 /* neighbor must be valid, eigrp_nbr_get creates if none existed */
75 assert(nbr);
76
77 nbr->recv_sequence_number = ntohl(eigrph->sequence);
78
79 while (s->endp > s->getp)
80 {
81 type = stream_getw(s);
82 if (type == EIGRP_TLV_IPv4_INT)
83 {
84 stream_set_getp(s, s->getp - sizeof(u_int16_t));
85
86 tlv = eigrp_read_ipv4_tlv(s);
87
88 struct prefix_ipv4 *dest_addr;
89 dest_addr = prefix_ipv4_new();
90 dest_addr->prefix = tlv->destination;
91 dest_addr->prefixlen = tlv->prefix_length;
92 struct eigrp_prefix_entry *dest = eigrp_topology_table_lookup_ipv4(
93 eigrp->topology_table, dest_addr);
94
95 /* If the destination exists (it should, but one never know)*/
96 if (dest != NULL)
97 {
98 struct eigrp_fsm_action_message *msg;
99 msg = XCALLOC(MTYPE_EIGRP_FSM_MSG,
100 sizeof(struct eigrp_fsm_action_message));
101 struct eigrp_neighbor_entry *entry = eigrp_prefix_entry_lookup(
102 dest->entries, nbr);
103 msg->packet_type = EIGRP_OPC_SIAQUERY;
104 msg->eigrp = eigrp;
105 msg->data_type = EIGRP_TLV_IPv4_INT;
106 msg->adv_router = nbr;
107 msg->data.ipv4_int_type = tlv;
108 msg->entry = entry;
109 msg->prefix = dest;
110 int event = eigrp_get_fsm_event(msg);
111 eigrp_fsm_event(msg, event);
112 }
113 eigrp_IPv4_InternalTLV_free (tlv);
114 }
115 }
116 eigrp_hello_send_ack(nbr);
117}
118
119void
120eigrp_send_siareply (struct eigrp_neighbor *nbr, struct eigrp_prefix_entry *pe)
121{
122 struct eigrp_packet *ep;
123 u_int16_t length = EIGRP_HEADER_LEN;
124
125 ep = eigrp_packet_new(nbr->ei->ifp->mtu);
126
127 /* Prepare EIGRP INIT UPDATE header */
128 eigrp_packet_header_init(EIGRP_OPC_SIAREPLY, nbr->ei, ep->s, 0,
129 nbr->ei->eigrp->sequence_number, 0);
130
131 // encode Authentication TLV, if needed
132 if((IF_DEF_PARAMS (nbr->ei->ifp)->auth_type == EIGRP_AUTH_TYPE_MD5) && (IF_DEF_PARAMS (nbr->ei->ifp)->auth_keychain != NULL))
133 {
134 length += eigrp_add_authTLV_MD5_to_stream(ep->s,nbr->ei);
135 }
136
137 length += eigrp_add_internalTLV_to_stream(ep->s, pe);
138
139 if((IF_DEF_PARAMS (nbr->ei->ifp)->auth_type == EIGRP_AUTH_TYPE_MD5) && (IF_DEF_PARAMS (nbr->ei->ifp)->auth_keychain != NULL))
140 {
141 eigrp_make_md5_digest(nbr->ei,ep->s, EIGRP_AUTH_UPDATE_FLAG);
142 }
143
144 /* EIGRP Checksum */
145 eigrp_packet_checksum(nbr->ei, ep->s, length);
146
147 ep->length = length;
148 ep->dst.s_addr = nbr->src.s_addr;
149
150 /*This ack number we await from neighbor*/
151 ep->sequence_number = nbr->ei->eigrp->sequence_number;
152
153 if (nbr->state == EIGRP_NEIGHBOR_UP)
154 {
155 /*Put packet to retransmission queue*/
156 eigrp_fifo_push_head(nbr->retrans_queue, ep);
157
158 if (nbr->retrans_queue->count == 1)
159 {
160 eigrp_send_packet_reliably(nbr);
161 }
162 }
163}
164
165