]>
git.proxmox.com Git - mirror_frr.git/blob - eigrpd/eigrp_reply.c
2 * EIGRP Sending and Receiving EIGRP Reply Packets.
3 * Copyright (C) 2013-2016
15 * This file is part of GNU Zebra.
17 * GNU Zebra is free software; you can redistribute it and/or modify it
18 * under the terms of the GNU General Public License as published by the
19 * Free Software Foundation; either version 2, or (at your option) any
22 * GNU Zebra is distributed in the hope that it will be useful, but
23 * WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
25 * General Public License for more details.
27 * You should have received a copy of the GNU General Public License
28 * along with GNU Zebra; see the file COPYING. If not, write to the Free
29 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
41 #include "sockunion.h"
51 #include "eigrpd/eigrp_structs.h"
52 #include "eigrpd/eigrpd.h"
53 #include "eigrpd/eigrp_interface.h"
54 #include "eigrpd/eigrp_neighbor.h"
55 #include "eigrpd/eigrp_packet.h"
56 #include "eigrpd/eigrp_zebra.h"
57 #include "eigrpd/eigrp_vty.h"
58 #include "eigrpd/eigrp_dump.h"
59 #include "eigrpd/eigrp_macros.h"
60 #include "eigrpd/eigrp_topology.h"
61 #include "eigrpd/eigrp_fsm.h"
62 #include "eigrpd/eigrp_memory.h"
65 eigrp_send_reply (struct eigrp_neighbor
*nbr
, struct eigrp_prefix_entry
*pe
)
67 struct eigrp_packet
*ep
;
68 u_int16_t length
= EIGRP_HEADER_LEN
;
70 struct access_list
*alist
;
71 struct prefix_list
*plist
;
72 struct access_list
*alist_i
;
73 struct prefix_list
*plist_i
;
75 struct eigrp_prefix_entry
*pe2
;
77 //TODO: Work in progress
79 /* get list from eigrp process */
81 pe2
= XCALLOC(MTYPE_EIGRP_PREFIX_ENTRY
, sizeof(struct eigrp_prefix_entry
));
82 memcpy(pe2
,pe
,sizeof(struct eigrp_prefix_entry
));
83 /* Get access-lists and prefix-lists from process and interface */
84 alist
= e
->list
[EIGRP_FILTER_OUT
];
85 plist
= e
->prefix
[EIGRP_FILTER_OUT
];
86 alist_i
= nbr
->ei
->list
[EIGRP_FILTER_OUT
];
87 plist_i
= nbr
->ei
->prefix
[EIGRP_FILTER_OUT
];
88 zlog_info("REPLY Send: Filtering");
90 zlog_info("REPLY SEND Prefix: %s", inet_ntoa(nbr
->src
));
91 /* Check if any list fits */
93 access_list_apply (alist
, (struct prefix
*) pe2
->destination_ipv4
) == FILTER_DENY
) ||
94 (plist
&& prefix_list_apply (plist
, (struct prefix
*) pe2
->destination_ipv4
) == PREFIX_DENY
)||
95 (alist_i
&& access_list_apply (alist_i
, (struct prefix
*) pe2
->destination_ipv4
) == FILTER_DENY
)||
96 (plist_i
&& prefix_list_apply (plist_i
, (struct prefix
*) pe2
->destination_ipv4
) == PREFIX_DENY
))
98 zlog_info("REPLY SEND: Setting Metric to max");
99 pe2
->reported_metric
.delay
= EIGRP_MAX_METRIC
;
104 zlog_info("REPLY SEND: Not setting metric");
111 ep
= eigrp_packet_new(nbr
->ei
->ifp
->mtu
);
113 /* Prepare EIGRP INIT UPDATE header */
114 eigrp_packet_header_init(EIGRP_OPC_REPLY
, nbr
->ei
, ep
->s
, 0,
115 nbr
->ei
->eigrp
->sequence_number
, 0);
117 // encode Authentication TLV, if needed
118 if((IF_DEF_PARAMS (nbr
->ei
->ifp
)->auth_type
== EIGRP_AUTH_TYPE_MD5
) &&
119 (IF_DEF_PARAMS (nbr
->ei
->ifp
)->auth_keychain
!= NULL
))
121 length
+= eigrp_add_authTLV_MD5_to_stream(ep
->s
,nbr
->ei
);
125 length
+= eigrp_add_internalTLV_to_stream(ep
->s
, pe2
);
127 if((IF_DEF_PARAMS (nbr
->ei
->ifp
)->auth_type
== EIGRP_AUTH_TYPE_MD5
) &&
128 (IF_DEF_PARAMS (nbr
->ei
->ifp
)->auth_keychain
!= NULL
))
130 eigrp_make_md5_digest(nbr
->ei
,ep
->s
, EIGRP_AUTH_UPDATE_FLAG
);
134 eigrp_packet_checksum(nbr
->ei
, ep
->s
, length
);
137 ep
->dst
.s_addr
= nbr
->src
.s_addr
;
139 /*This ack number we await from neighbor*/
140 ep
->sequence_number
= nbr
->ei
->eigrp
->sequence_number
;
142 /*Put packet to retransmission queue*/
143 eigrp_fifo_push_head(nbr
->retrans_queue
, ep
);
145 if (nbr
->retrans_queue
->count
== 1)
147 eigrp_send_packet_reliably(nbr
);
151 /*EIGRP REPLY read function*/
153 eigrp_reply_receive (struct eigrp
*eigrp
, struct ip
*iph
, struct eigrp_header
*eigrph
,
154 struct stream
* s
, struct eigrp_interface
*ei
, int size
)
156 struct eigrp_neighbor
*nbr
;
157 struct TLV_IPv4_Internal_type
*tlv
;
159 struct access_list
*alist
;
160 struct prefix_list
*plist
;
161 struct access_list
*alist_i
;
162 struct prefix_list
*plist_i
;
167 /* increment statistics. */
170 /* get neighbor struct */
171 nbr
= eigrp_nbr_get(ei
, eigrph
, iph
);
173 /* neighbor must be valid, eigrp_nbr_get creates if none existed */
176 nbr
->recv_sequence_number
= ntohl(eigrph
->sequence
);
178 while (s
->endp
> s
->getp
)
180 type
= stream_getw(s
);
181 if (type
== EIGRP_TLV_IPv4_INT
)
183 stream_set_getp(s
, s
->getp
- sizeof(u_int16_t
));
185 tlv
= eigrp_read_ipv4_tlv(s
);
187 struct prefix_ipv4
*dest_addr
;
188 dest_addr
= prefix_ipv4_new();
189 dest_addr
->prefix
= tlv
->destination
;
190 dest_addr
->prefixlen
= tlv
->prefix_length
;
191 struct eigrp_prefix_entry
*dest
=
192 eigrp_topology_table_lookup_ipv4 (eigrp
->topology_table
, dest_addr
);
194 * Destination must exists
198 struct eigrp_fsm_action_message
*msg
;
199 msg
= XCALLOC(MTYPE_EIGRP_FSM_MSG
,
200 sizeof(struct eigrp_fsm_action_message
));
201 struct eigrp_neighbor_entry
*entry
=
202 eigrp_prefix_entry_lookup(dest
->entries
, nbr
);
207 //TODO: Work in progress
208 /* get list from eigrp process */
210 /* Get access-lists and prefix-lists from process and interface */
211 alist
= e
->list
[EIGRP_FILTER_IN
];
212 plist
= e
->prefix
[EIGRP_FILTER_IN
];
213 alist_i
= ei
->list
[EIGRP_FILTER_IN
];
214 plist_i
= ei
->prefix
[EIGRP_FILTER_IN
];
215 zlog_info("REPLY Receive: Filtering");
216 zlog_info("REPLY RECEIVE Prefix: %s", inet_ntoa(dest_addr
->prefix
));
217 /* Check if any list fits */
218 if ((alist
&& access_list_apply (alist
,
219 (struct prefix
*) dest_addr
) == FILTER_DENY
)||
220 (plist
&& prefix_list_apply (plist
,
221 (struct prefix
*) dest_addr
) == PREFIX_DENY
)||
222 (alist_i
&& access_list_apply (alist_i
,
223 (struct prefix
*) dest_addr
) == FILTER_DENY
)||
224 (plist_i
&& prefix_list_apply (plist_i
,
225 (struct prefix
*) dest_addr
) == PREFIX_DENY
))
227 zlog_info("REPLY RECEIVE: Setting metric to max");
228 tlv
->metric
.delay
= EIGRP_MAX_METRIC
;
229 zlog_info("REPLY RECEIVE Prefix: %s", inet_ntoa(dest_addr
->prefix
));
231 zlog_info("REPLY RECEIVE: Not setting metric");
237 msg
->packet_type
= EIGRP_OPC_REPLY
;
239 msg
->data_type
= EIGRP_TLV_IPv4_INT
;
240 msg
->adv_router
= nbr
;
241 msg
->data
.ipv4_int_type
= tlv
;
244 int event
= eigrp_get_fsm_event(msg
);
245 eigrp_fsm_event(msg
, event
);
248 eigrp_IPv4_InternalTLV_free (tlv
);
251 eigrp_hello_send_ack(nbr
);