]>
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_MTYPE_STATIC(RIPNGD
, RIPNG_OFFSET_LIST
, "RIPng offset lst")
38 #define OFFSET_LIST_IN_NAME(O) ((O)->direct[RIPNG_OFFSET_LIST_IN].alist_name)
39 #define OFFSET_LIST_IN_METRIC(O) ((O)->direct[RIPNG_OFFSET_LIST_IN].metric)
41 #define OFFSET_LIST_OUT_NAME(O) ((O)->direct[RIPNG_OFFSET_LIST_OUT].alist_name)
42 #define OFFSET_LIST_OUT_METRIC(O) ((O)->direct[RIPNG_OFFSET_LIST_OUT].metric)
44 struct ripng_offset_list
*ripng_offset_list_new(struct ripng
*ripng
,
47 struct ripng_offset_list
*new;
49 new = XCALLOC(MTYPE_RIPNG_OFFSET_LIST
,
50 sizeof(struct ripng_offset_list
));
52 new->ifname
= strdup(ifname
);
53 listnode_add_sort(ripng
->offset_list_master
, new);
58 void ripng_offset_list_del(struct ripng_offset_list
*offset
)
60 listnode_delete(offset
->ripng
->offset_list_master
, offset
);
61 ripng_offset_list_free(offset
);
64 void ripng_offset_list_free(struct ripng_offset_list
*offset
)
66 if (OFFSET_LIST_IN_NAME(offset
))
67 free(OFFSET_LIST_IN_NAME(offset
));
68 if (OFFSET_LIST_OUT_NAME(offset
))
69 free(OFFSET_LIST_OUT_NAME(offset
));
71 XFREE(MTYPE_RIPNG_OFFSET_LIST
, offset
);
74 struct ripng_offset_list
*ripng_offset_list_lookup(struct ripng
*ripng
,
77 struct ripng_offset_list
*offset
;
78 struct listnode
*node
, *nnode
;
80 for (ALL_LIST_ELEMENTS(ripng
->offset_list_master
, node
, nnode
,
82 if (strcmp(offset
->ifname
, ifname
) == 0)
88 /* If metric is modifed return 1. */
89 int ripng_offset_list_apply_in(struct ripng
*ripng
, struct prefix_ipv6
*p
,
90 struct interface
*ifp
, uint8_t *metric
)
92 struct ripng_offset_list
*offset
;
93 struct access_list
*alist
;
95 /* Look up offset-list with interface name. */
96 offset
= ripng_offset_list_lookup(ripng
, ifp
->name
);
97 if (offset
&& OFFSET_LIST_IN_NAME(offset
)) {
98 alist
= access_list_lookup(AFI_IP6
,
99 OFFSET_LIST_IN_NAME(offset
));
102 && access_list_apply(alist
, (struct prefix
*)p
)
104 *metric
+= OFFSET_LIST_IN_METRIC(offset
);
109 /* Look up offset-list without interface name. */
110 offset
= ripng_offset_list_lookup(ripng
, "*");
111 if (offset
&& OFFSET_LIST_IN_NAME(offset
)) {
112 alist
= access_list_lookup(AFI_IP6
,
113 OFFSET_LIST_IN_NAME(offset
));
116 && access_list_apply(alist
, (struct prefix
*)p
)
118 *metric
+= OFFSET_LIST_IN_METRIC(offset
);
126 /* If metric is modifed return 1. */
127 int ripng_offset_list_apply_out(struct ripng
*ripng
, struct prefix_ipv6
*p
,
128 struct interface
*ifp
, uint8_t *metric
)
130 struct ripng_offset_list
*offset
;
131 struct access_list
*alist
;
133 /* Look up offset-list with interface name. */
134 offset
= ripng_offset_list_lookup(ripng
, ifp
->name
);
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
);
148 /* Look up offset-list without interface name. */
149 offset
= ripng_offset_list_lookup(ripng
, "*");
150 if (offset
&& OFFSET_LIST_OUT_NAME(offset
)) {
151 alist
= access_list_lookup(AFI_IP6
,
152 OFFSET_LIST_OUT_NAME(offset
));
155 && access_list_apply(alist
, (struct prefix
*)p
)
157 *metric
+= OFFSET_LIST_OUT_METRIC(offset
);
165 int offset_list_cmp(struct ripng_offset_list
*o1
, struct ripng_offset_list
*o2
)
167 return strcmp(o1
->ifname
, o2
->ifname
);