]>
git.proxmox.com Git - mirror_frr.git/blob - ripngd/ripng_offset.c
1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Copyright (C) 2000 Kunihiro Ishiguro <kunihiro@zebra.org>
6 /* RIPng support by Vincent Jardin <vincent.jardin@6wind.com>
7 * Copyright (C) 2002 6WIND
19 #include "ripngd/ripngd.h"
21 DEFINE_MTYPE_STATIC(RIPNGD
, RIPNG_OFFSET_LIST
, "RIPng offset lst");
23 #define OFFSET_LIST_IN_NAME(O) ((O)->direct[RIPNG_OFFSET_LIST_IN].alist_name)
24 #define OFFSET_LIST_IN_METRIC(O) ((O)->direct[RIPNG_OFFSET_LIST_IN].metric)
26 #define OFFSET_LIST_OUT_NAME(O) ((O)->direct[RIPNG_OFFSET_LIST_OUT].alist_name)
27 #define OFFSET_LIST_OUT_METRIC(O) ((O)->direct[RIPNG_OFFSET_LIST_OUT].metric)
29 struct ripng_offset_list
*ripng_offset_list_new(struct ripng
*ripng
,
32 struct ripng_offset_list
*new;
34 new = XCALLOC(MTYPE_RIPNG_OFFSET_LIST
,
35 sizeof(struct ripng_offset_list
));
37 new->ifname
= strdup(ifname
);
38 listnode_add_sort(ripng
->offset_list_master
, new);
43 void ripng_offset_list_del(struct ripng_offset_list
*offset
)
45 listnode_delete(offset
->ripng
->offset_list_master
, offset
);
46 ripng_offset_list_free(offset
);
49 void ripng_offset_list_free(struct ripng_offset_list
*offset
)
51 if (OFFSET_LIST_IN_NAME(offset
))
52 free(OFFSET_LIST_IN_NAME(offset
));
53 if (OFFSET_LIST_OUT_NAME(offset
))
54 free(OFFSET_LIST_OUT_NAME(offset
));
56 XFREE(MTYPE_RIPNG_OFFSET_LIST
, offset
);
59 struct ripng_offset_list
*ripng_offset_list_lookup(struct ripng
*ripng
,
62 struct ripng_offset_list
*offset
;
63 struct listnode
*node
, *nnode
;
65 for (ALL_LIST_ELEMENTS(ripng
->offset_list_master
, node
, nnode
,
67 if (strcmp(offset
->ifname
, ifname
) == 0)
73 /* If metric is modified return 1. */
74 int ripng_offset_list_apply_in(struct ripng
*ripng
, struct prefix_ipv6
*p
,
75 struct interface
*ifp
, uint8_t *metric
)
77 struct ripng_offset_list
*offset
;
78 struct access_list
*alist
;
80 /* Look up offset-list with interface name. */
81 offset
= ripng_offset_list_lookup(ripng
, ifp
->name
);
82 if (offset
&& OFFSET_LIST_IN_NAME(offset
)) {
83 alist
= access_list_lookup(AFI_IP6
,
84 OFFSET_LIST_IN_NAME(offset
));
87 && access_list_apply(alist
, (struct prefix
*)p
)
89 *metric
+= OFFSET_LIST_IN_METRIC(offset
);
94 /* Look up offset-list without interface name. */
95 offset
= ripng_offset_list_lookup(ripng
, "*");
96 if (offset
&& OFFSET_LIST_IN_NAME(offset
)) {
97 alist
= access_list_lookup(AFI_IP6
,
98 OFFSET_LIST_IN_NAME(offset
));
101 && access_list_apply(alist
, (struct prefix
*)p
)
103 *metric
+= OFFSET_LIST_IN_METRIC(offset
);
111 /* If metric is modified return 1. */
112 int ripng_offset_list_apply_out(struct ripng
*ripng
, struct prefix_ipv6
*p
,
113 struct interface
*ifp
, uint8_t *metric
)
115 struct ripng_offset_list
*offset
;
116 struct access_list
*alist
;
118 /* Look up offset-list with interface name. */
119 offset
= ripng_offset_list_lookup(ripng
, ifp
->name
);
120 if (offset
&& OFFSET_LIST_OUT_NAME(offset
)) {
121 alist
= access_list_lookup(AFI_IP6
,
122 OFFSET_LIST_OUT_NAME(offset
));
125 && access_list_apply(alist
, (struct prefix
*)p
)
127 *metric
+= OFFSET_LIST_OUT_METRIC(offset
);
133 /* Look up offset-list without interface name. */
134 offset
= ripng_offset_list_lookup(ripng
, "*");
135 if (offset
&& OFFSET_LIST_OUT_NAME(offset
)) {
136 alist
= access_list_lookup(AFI_IP6
,
137 OFFSET_LIST_OUT_NAME(offset
));
140 && access_list_apply(alist
, (struct prefix
*)p
)
142 *metric
+= OFFSET_LIST_OUT_METRIC(offset
);
150 int offset_list_cmp(struct ripng_offset_list
*o1
, struct ripng_offset_list
*o2
)
152 return strcmp(o1
->ifname
, o2
->ifname
);