]>
git.proxmox.com Git - mirror_frr.git/blob - ripngd/ripng_nexthop.c
2 * Copyright (C) 2002 6WIND <vincent.jardin@6wind.com>
4 * This file is part of GNU Zebra.
6 * GNU Zebra is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2, or (at your option) any
11 * GNU Zebra is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; see the file COPYING; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 /* This file is required in order to support properly the RIPng nexthop
27 /* For struct udphdr. */
28 #include <netinet/udp.h>
38 #include "ripngd/ripngd.h"
39 #include "ripngd/ripng_debug.h"
40 #include "ripngd/ripng_nexthop.h"
44 #define min(a, b) ((a) < (b) ? (a) : (b))
46 struct ripng_rte_data
{
47 struct prefix_ipv6
*p
;
48 struct ripng_info
*rinfo
;
49 struct ripng_aggregate
*aggregate
;
52 void _ripng_rte_del(struct ripng_rte_data
*A
);
53 int _ripng_rte_cmp(struct ripng_rte_data
*A
, struct ripng_rte_data
*B
);
55 #define METRIC_OUT(a) \
56 ((a)->rinfo ? (a)->rinfo->metric_out : (a)->aggregate->metric_out)
57 #define NEXTHOP_OUT_PTR(a) \
58 ((a)->rinfo ? &((a)->rinfo->nexthop_out) : &((a)->aggregate->nexthop_out))
60 ((a)->rinfo ? (a)->rinfo->tag_out : (a)->aggregate->tag_out)
67 rte
->cmp
= (int (*)(void *, void *)) _ripng_rte_cmp
;
68 rte
->del
= (void (*)(void *)) _ripng_rte_del
;
74 ripng_rte_free(struct list
*ripng_rte_list
) {
75 list_delete(ripng_rte_list
);
80 _ripng_rte_del(struct ripng_rte_data
*A
) {
81 XFREE(MTYPE_RIPNG_RTE_DATA
, A
);
90 _ripng_rte_cmp(struct ripng_rte_data
*A
, struct ripng_rte_data
*B
) {
91 return addr6_cmp(NEXTHOP_OUT_PTR(A
), NEXTHOP_OUT_PTR(B
));
94 /* Add routing table entry */
96 ripng_rte_add(struct list
*ripng_rte_list
, struct prefix_ipv6
*p
,
97 struct ripng_info
*rinfo
, struct ripng_aggregate
*aggregate
) {
99 struct ripng_rte_data
*data
;
101 /* At least one should not be null */
102 assert(!rinfo
|| !aggregate
);
104 data
= XMALLOC(MTYPE_RIPNG_RTE_DATA
, sizeof(*data
));
107 data
->aggregate
= aggregate
;
109 listnode_add_sort(ripng_rte_list
, data
);
112 /* Send the RTE with the nexthop support
115 ripng_rte_send(struct list
*ripng_rte_list
, struct interface
*ifp
,
116 struct sockaddr_in6
*to
) {
118 struct ripng_rte_data
*data
;
119 struct listnode
*node
, *nnode
;
121 struct in6_addr last_nexthop
;
122 struct in6_addr myself_nexthop
;
130 /* Most of the time, there is no nexthop */
131 memset(&last_nexthop
, 0, sizeof(last_nexthop
));
133 /* Use myself_nexthop if the nexthop is not a link-local address, because
134 * we remain a right path without beeing the optimal one.
136 memset(&myself_nexthop
, 0, sizeof(myself_nexthop
));
138 /* Output stream get from ripng structre. XXX this should be
139 interface structure. */
142 /* Reset stream and RTE counter. */
150 rtemax
= (min (mtu
, RIPNG_MAX_PACKET_SIZE
) -
152 sizeof (struct udphdr
) -
153 sizeof (struct ripng_packet
) +
154 sizeof (struct rte
)) / sizeof (struct rte
);
156 for (ALL_LIST_ELEMENTS (ripng_rte_list
, node
, nnode
, data
)) {
157 /* (2.1) Next hop support */
158 if (!IPV6_ADDR_SAME(&last_nexthop
, NEXTHOP_OUT_PTR(data
))) {
160 /* A nexthop entry should be at least followed by 1 RTE */
161 if (num
== (rtemax
-1)) {
162 ret
= ripng_send_packet ((caddr_t
) STREAM_DATA (s
), stream_get_endp (s
),
165 if (ret
>= 0 && IS_RIPNG_DEBUG_SEND
)
166 ripng_packet_dump((struct ripng_packet
*)STREAM_DATA (s
),
167 stream_get_endp(s
), "SEND");
172 /* Add the nexthop (2.1) */
174 /* If the received next hop address is not a link-local address,
175 * it should be treated as 0:0:0:0:0:0:0:0.
177 if (!IN6_IS_ADDR_LINKLOCAL(NEXTHOP_OUT_PTR(data
)))
178 last_nexthop
= myself_nexthop
;
180 last_nexthop
= *NEXTHOP_OUT_PTR(data
);
182 num
= ripng_write_rte(num
, s
, NULL
, &last_nexthop
, 0, RIPNG_METRIC_NEXTHOP
);
184 /* Rewrite the nexthop for each new packet */
185 if ((num
== 0) && !IPV6_ADDR_SAME(&last_nexthop
, &myself_nexthop
))
186 num
= ripng_write_rte(num
, s
, NULL
, &last_nexthop
, 0, RIPNG_METRIC_NEXTHOP
);
188 num
= ripng_write_rte(num
, s
, data
->p
, NULL
,
189 TAG_OUT(data
), METRIC_OUT(data
));
192 ret
= ripng_send_packet ((caddr_t
) STREAM_DATA (s
), stream_get_endp (s
),
195 if (ret
>= 0 && IS_RIPNG_DEBUG_SEND
)
196 ripng_packet_dump((struct ripng_packet
*)STREAM_DATA (s
),
197 stream_get_endp(s
), "SEND");
203 /* If unwritten RTE exist, flush it. */
205 ret
= ripng_send_packet ((caddr_t
) STREAM_DATA (s
), stream_get_endp (s
),
208 if (ret
>= 0 && IS_RIPNG_DEBUG_SEND
)
209 ripng_packet_dump ((struct ripng_packet
*)STREAM_DATA (s
),
210 stream_get_endp (s
), "SEND");