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