]>
git.proxmox.com Git - mirror_frr.git/blob - ripngd/ripng_offset.c
2 * Copyright (C) 2000 Kunihiro Ishiguro <kunihiro@zebra.org>
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 /* RIPng support by Vincent Jardin <vincent.jardin@6wind.com>
22 * Copyright (C) 2002 6WIND
34 #include "ripngd/ripngd.h"
36 #define OFFSET_LIST_IN_NAME(O) ((O)->direct[RIPNG_OFFSET_LIST_IN].alist_name)
37 #define OFFSET_LIST_IN_METRIC(O) ((O)->direct[RIPNG_OFFSET_LIST_IN].metric)
39 #define OFFSET_LIST_OUT_NAME(O) ((O)->direct[RIPNG_OFFSET_LIST_OUT].alist_name)
40 #define OFFSET_LIST_OUT_METRIC(O) ((O)->direct[RIPNG_OFFSET_LIST_OUT].metric)
42 struct ripng_offset_list
*ripng_offset_list_new(struct ripng
*ripng
,
45 struct ripng_offset_list
*new;
47 new = XCALLOC(MTYPE_RIPNG_OFFSET_LIST
,
48 sizeof(struct ripng_offset_list
));
50 new->ifname
= strdup(ifname
);
51 listnode_add_sort(ripng
->offset_list_master
, new);
56 void ripng_offset_list_del(struct ripng_offset_list
*offset
)
58 listnode_delete(offset
->ripng
->offset_list_master
, offset
);
59 ripng_offset_list_free(offset
);
62 void ripng_offset_list_free(struct ripng_offset_list
*offset
)
64 if (OFFSET_LIST_IN_NAME(offset
))
65 free(OFFSET_LIST_IN_NAME(offset
));
66 if (OFFSET_LIST_OUT_NAME(offset
))
67 free(OFFSET_LIST_OUT_NAME(offset
));
69 XFREE(MTYPE_RIPNG_OFFSET_LIST
, offset
);
72 struct ripng_offset_list
*ripng_offset_list_lookup(struct ripng
*ripng
,
75 struct ripng_offset_list
*offset
;
76 struct listnode
*node
, *nnode
;
78 for (ALL_LIST_ELEMENTS(ripng
->offset_list_master
, node
, nnode
,
80 if (strcmp(offset
->ifname
, ifname
) == 0)
86 /* If metric is modifed return 1. */
87 int ripng_offset_list_apply_in(struct ripng
*ripng
, struct prefix_ipv6
*p
,
88 struct interface
*ifp
, uint8_t *metric
)
90 struct ripng_offset_list
*offset
;
91 struct access_list
*alist
;
93 /* Look up offset-list with interface name. */
94 offset
= ripng_offset_list_lookup(ripng
, ifp
->name
);
95 if (offset
&& OFFSET_LIST_IN_NAME(offset
)) {
96 alist
= access_list_lookup(AFI_IP6
,
97 OFFSET_LIST_IN_NAME(offset
));
100 && access_list_apply(alist
, (struct prefix
*)p
)
102 *metric
+= OFFSET_LIST_IN_METRIC(offset
);
107 /* Look up offset-list without interface name. */
108 offset
= ripng_offset_list_lookup(ripng
, "*");
109 if (offset
&& OFFSET_LIST_IN_NAME(offset
)) {
110 alist
= access_list_lookup(AFI_IP6
,
111 OFFSET_LIST_IN_NAME(offset
));
114 && access_list_apply(alist
, (struct prefix
*)p
)
116 *metric
+= OFFSET_LIST_IN_METRIC(offset
);
124 /* If metric is modifed return 1. */
125 int ripng_offset_list_apply_out(struct ripng
*ripng
, struct prefix_ipv6
*p
,
126 struct interface
*ifp
, uint8_t *metric
)
128 struct ripng_offset_list
*offset
;
129 struct access_list
*alist
;
131 /* Look up offset-list with interface name. */
132 offset
= ripng_offset_list_lookup(ripng
, ifp
->name
);
133 if (offset
&& OFFSET_LIST_OUT_NAME(offset
)) {
134 alist
= access_list_lookup(AFI_IP6
,
135 OFFSET_LIST_OUT_NAME(offset
));
138 && access_list_apply(alist
, (struct prefix
*)p
)
140 *metric
+= OFFSET_LIST_OUT_METRIC(offset
);
146 /* Look up offset-list without interface name. */
147 offset
= ripng_offset_list_lookup(ripng
, "*");
148 if (offset
&& OFFSET_LIST_OUT_NAME(offset
)) {
149 alist
= access_list_lookup(AFI_IP6
,
150 OFFSET_LIST_OUT_NAME(offset
));
153 && access_list_apply(alist
, (struct prefix
*)p
)
155 *metric
+= OFFSET_LIST_OUT_METRIC(offset
);
163 int offset_list_cmp(struct ripng_offset_list
*o1
, struct ripng_offset_list
*o2
)
165 return strcmp(o1
->ifname
, o2
->ifname
);