]>
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(const char *ifname
)
44 struct ripng_offset_list
*new;
46 new = XCALLOC(MTYPE_RIPNG_OFFSET_LIST
,
47 sizeof(struct ripng_offset_list
));
48 new->ifname
= strdup(ifname
);
49 listnode_add_sort(ripng
->offset_list_master
, new);
54 void ripng_offset_list_del(struct ripng_offset_list
*offset
)
56 listnode_delete(ripng
->offset_list_master
, offset
);
57 if (OFFSET_LIST_IN_NAME(offset
))
58 free(OFFSET_LIST_IN_NAME(offset
));
59 if (OFFSET_LIST_OUT_NAME(offset
))
60 free(OFFSET_LIST_OUT_NAME(offset
));
62 XFREE(MTYPE_RIPNG_OFFSET_LIST
, offset
);
65 struct ripng_offset_list
*ripng_offset_list_lookup(const char *ifname
)
67 struct ripng_offset_list
*offset
;
68 struct listnode
*node
, *nnode
;
70 for (ALL_LIST_ELEMENTS(ripng
->offset_list_master
, node
, nnode
,
72 if (strcmp(offset
->ifname
, ifname
) == 0)
78 /* If metric is modifed return 1. */
79 int ripng_offset_list_apply_in(struct prefix_ipv6
*p
, struct interface
*ifp
,
82 struct ripng_offset_list
*offset
;
83 struct access_list
*alist
;
85 /* Look up offset-list with interface name. */
86 offset
= ripng_offset_list_lookup(ifp
->name
);
87 if (offset
&& OFFSET_LIST_IN_NAME(offset
)) {
88 alist
= access_list_lookup(AFI_IP6
,
89 OFFSET_LIST_IN_NAME(offset
));
92 && access_list_apply(alist
, (struct prefix
*)p
)
94 *metric
+= OFFSET_LIST_IN_METRIC(offset
);
99 /* Look up offset-list without interface name. */
100 offset
= ripng_offset_list_lookup("*");
101 if (offset
&& OFFSET_LIST_IN_NAME(offset
)) {
102 alist
= access_list_lookup(AFI_IP6
,
103 OFFSET_LIST_IN_NAME(offset
));
106 && access_list_apply(alist
, (struct prefix
*)p
)
108 *metric
+= OFFSET_LIST_IN_METRIC(offset
);
116 /* If metric is modifed return 1. */
117 int ripng_offset_list_apply_out(struct prefix_ipv6
*p
, struct interface
*ifp
,
120 struct ripng_offset_list
*offset
;
121 struct access_list
*alist
;
123 /* Look up offset-list with interface name. */
124 offset
= ripng_offset_list_lookup(ifp
->name
);
125 if (offset
&& OFFSET_LIST_OUT_NAME(offset
)) {
126 alist
= access_list_lookup(AFI_IP6
,
127 OFFSET_LIST_OUT_NAME(offset
));
130 && access_list_apply(alist
, (struct prefix
*)p
)
132 *metric
+= OFFSET_LIST_OUT_METRIC(offset
);
138 /* Look up offset-list without interface name. */
139 offset
= ripng_offset_list_lookup("*");
140 if (offset
&& OFFSET_LIST_OUT_NAME(offset
)) {
141 alist
= access_list_lookup(AFI_IP6
,
142 OFFSET_LIST_OUT_NAME(offset
));
145 && access_list_apply(alist
, (struct prefix
*)p
)
147 *metric
+= OFFSET_LIST_OUT_METRIC(offset
);
155 int offset_list_cmp(struct ripng_offset_list
*o1
, struct ripng_offset_list
*o2
)
157 return strcmp(o1
->ifname
, o2
->ifname
);