Line data Source code
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 3 : DEFINE_MTYPE_STATIC(RIPNGD, RIPNG_OFFSET_LIST, "RIPng offset lst");
37 :
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)
40 :
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)
43 :
44 0 : struct ripng_offset_list *ripng_offset_list_new(struct ripng *ripng,
45 : const char *ifname)
46 : {
47 0 : struct ripng_offset_list *new;
48 :
49 0 : new = XCALLOC(MTYPE_RIPNG_OFFSET_LIST,
50 : sizeof(struct ripng_offset_list));
51 0 : new->ripng = ripng;
52 0 : new->ifname = strdup(ifname);
53 0 : listnode_add_sort(ripng->offset_list_master, new);
54 :
55 0 : return new;
56 : }
57 :
58 0 : void ripng_offset_list_del(struct ripng_offset_list *offset)
59 : {
60 0 : listnode_delete(offset->ripng->offset_list_master, offset);
61 0 : ripng_offset_list_free(offset);
62 0 : }
63 :
64 0 : void ripng_offset_list_free(struct ripng_offset_list *offset)
65 : {
66 0 : if (OFFSET_LIST_IN_NAME(offset))
67 0 : free(OFFSET_LIST_IN_NAME(offset));
68 0 : if (OFFSET_LIST_OUT_NAME(offset))
69 0 : free(OFFSET_LIST_OUT_NAME(offset));
70 0 : free(offset->ifname);
71 0 : XFREE(MTYPE_RIPNG_OFFSET_LIST, offset);
72 0 : }
73 :
74 0 : struct ripng_offset_list *ripng_offset_list_lookup(struct ripng *ripng,
75 : const char *ifname)
76 : {
77 0 : struct ripng_offset_list *offset;
78 0 : struct listnode *node, *nnode;
79 :
80 0 : for (ALL_LIST_ELEMENTS(ripng->offset_list_master, node, nnode,
81 : offset)) {
82 0 : if (strcmp(offset->ifname, ifname) == 0)
83 0 : return offset;
84 : }
85 : return NULL;
86 : }
87 :
88 : /* If metric is modified return 1. */
89 0 : int ripng_offset_list_apply_in(struct ripng *ripng, struct prefix_ipv6 *p,
90 : struct interface *ifp, uint8_t *metric)
91 : {
92 0 : struct ripng_offset_list *offset;
93 0 : struct access_list *alist;
94 :
95 : /* Look up offset-list with interface name. */
96 0 : offset = ripng_offset_list_lookup(ripng, ifp->name);
97 0 : if (offset && OFFSET_LIST_IN_NAME(offset)) {
98 0 : alist = access_list_lookup(AFI_IP6,
99 : OFFSET_LIST_IN_NAME(offset));
100 :
101 0 : if (alist
102 0 : && access_list_apply(alist, (struct prefix *)p)
103 : == FILTER_PERMIT) {
104 0 : *metric += OFFSET_LIST_IN_METRIC(offset);
105 0 : return 1;
106 : }
107 0 : return 0;
108 : }
109 : /* Look up offset-list without interface name. */
110 0 : offset = ripng_offset_list_lookup(ripng, "*");
111 0 : if (offset && OFFSET_LIST_IN_NAME(offset)) {
112 0 : alist = access_list_lookup(AFI_IP6,
113 : OFFSET_LIST_IN_NAME(offset));
114 :
115 0 : if (alist
116 0 : && access_list_apply(alist, (struct prefix *)p)
117 : == FILTER_PERMIT) {
118 0 : *metric += OFFSET_LIST_IN_METRIC(offset);
119 0 : return 1;
120 : }
121 0 : return 0;
122 : }
123 : return 0;
124 : }
125 :
126 : /* If metric is modified return 1. */
127 0 : int ripng_offset_list_apply_out(struct ripng *ripng, struct prefix_ipv6 *p,
128 : struct interface *ifp, uint8_t *metric)
129 : {
130 0 : struct ripng_offset_list *offset;
131 0 : struct access_list *alist;
132 :
133 : /* Look up offset-list with interface name. */
134 0 : offset = ripng_offset_list_lookup(ripng, ifp->name);
135 0 : if (offset && OFFSET_LIST_OUT_NAME(offset)) {
136 0 : alist = access_list_lookup(AFI_IP6,
137 : OFFSET_LIST_OUT_NAME(offset));
138 :
139 0 : if (alist
140 0 : && access_list_apply(alist, (struct prefix *)p)
141 : == FILTER_PERMIT) {
142 0 : *metric += OFFSET_LIST_OUT_METRIC(offset);
143 0 : return 1;
144 : }
145 0 : return 0;
146 : }
147 :
148 : /* Look up offset-list without interface name. */
149 0 : offset = ripng_offset_list_lookup(ripng, "*");
150 0 : if (offset && OFFSET_LIST_OUT_NAME(offset)) {
151 0 : alist = access_list_lookup(AFI_IP6,
152 : OFFSET_LIST_OUT_NAME(offset));
153 :
154 0 : if (alist
155 0 : && access_list_apply(alist, (struct prefix *)p)
156 : == FILTER_PERMIT) {
157 0 : *metric += OFFSET_LIST_OUT_METRIC(offset);
158 0 : return 1;
159 : }
160 0 : return 0;
161 : }
162 : return 0;
163 : }
164 :
165 0 : int offset_list_cmp(struct ripng_offset_list *o1, struct ripng_offset_list *o2)
166 : {
167 0 : return strcmp(o1->ifname, o2->ifname);
168 : }
|