]> git.proxmox.com Git - mirror_frr.git/blob - ripngd/ripng_offset.c
ripngd: move "ripng_offset_list_master" to the ripng structure
[mirror_frr.git] / ripngd / ripng_offset.c
1 /* RIPng offset-list
2 * Copyright (C) 2000 Kunihiro Ishiguro <kunihiro@zebra.org>
3 *
4 * This file is part of GNU Zebra.
5 *
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
9 * later version.
10 *
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.
15 *
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
19 */
20
21 /* RIPng support by Vincent Jardin <vincent.jardin@6wind.com>
22 * Copyright (C) 2002 6WIND
23 */
24
25 #include <zebra.h>
26
27 #include "if.h"
28 #include "prefix.h"
29 #include "filter.h"
30 #include "command.h"
31 #include "linklist.h"
32 #include "memory.h"
33
34 #include "ripngd/ripngd.h"
35
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)
38
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)
41
42 struct ripng_offset_list *ripng_offset_list_new(const char *ifname)
43 {
44 struct ripng_offset_list *new;
45
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);
50
51 return new;
52 }
53
54 void ripng_offset_list_del(struct ripng_offset_list *offset)
55 {
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));
61 free(offset->ifname);
62 XFREE(MTYPE_RIPNG_OFFSET_LIST, offset);
63 }
64
65 struct ripng_offset_list *ripng_offset_list_lookup(const char *ifname)
66 {
67 struct ripng_offset_list *offset;
68 struct listnode *node, *nnode;
69
70 for (ALL_LIST_ELEMENTS(ripng->offset_list_master, node, nnode,
71 offset)) {
72 if (strcmp(offset->ifname, ifname) == 0)
73 return offset;
74 }
75 return NULL;
76 }
77
78 /* If metric is modifed return 1. */
79 int ripng_offset_list_apply_in(struct prefix_ipv6 *p, struct interface *ifp,
80 uint8_t *metric)
81 {
82 struct ripng_offset_list *offset;
83 struct access_list *alist;
84
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));
90
91 if (alist
92 && access_list_apply(alist, (struct prefix *)p)
93 == FILTER_PERMIT) {
94 *metric += OFFSET_LIST_IN_METRIC(offset);
95 return 1;
96 }
97 return 0;
98 }
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));
104
105 if (alist
106 && access_list_apply(alist, (struct prefix *)p)
107 == FILTER_PERMIT) {
108 *metric += OFFSET_LIST_IN_METRIC(offset);
109 return 1;
110 }
111 return 0;
112 }
113 return 0;
114 }
115
116 /* If metric is modifed return 1. */
117 int ripng_offset_list_apply_out(struct prefix_ipv6 *p, struct interface *ifp,
118 uint8_t *metric)
119 {
120 struct ripng_offset_list *offset;
121 struct access_list *alist;
122
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));
128
129 if (alist
130 && access_list_apply(alist, (struct prefix *)p)
131 == FILTER_PERMIT) {
132 *metric += OFFSET_LIST_OUT_METRIC(offset);
133 return 1;
134 }
135 return 0;
136 }
137
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));
143
144 if (alist
145 && access_list_apply(alist, (struct prefix *)p)
146 == FILTER_PERMIT) {
147 *metric += OFFSET_LIST_OUT_METRIC(offset);
148 return 1;
149 }
150 return 0;
151 }
152 return 0;
153 }
154
155 int offset_list_cmp(struct ripng_offset_list *o1, struct ripng_offset_list *o2)
156 {
157 return strcmp(o1->ifname, o2->ifname);
158 }