]>
Commit | Line | Data |
---|---|---|
a94434b6 | 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 | * | |
896014f4 DL |
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 | |
a94434b6 | 19 | */ |
20 | ||
d62a17ae | 21 | /* RIPng support by Vincent Jardin <vincent.jardin@6wind.com> |
22 | * Copyright (C) 2002 6WIND | |
23 | */ | |
a94434b6 | 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 | ||
6ac29a51 PJ |
34 | #include "ripngd/ripngd.h" |
35 | ||
b09956ca RW |
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) | |
a94434b6 | 41 | |
5c84b9a5 RW |
42 | struct ripng_offset_list *ripng_offset_list_new(struct ripng *ripng, |
43 | const char *ifname) | |
a94434b6 | 44 | { |
d62a17ae | 45 | struct ripng_offset_list *new; |
a94434b6 | 46 | |
d62a17ae | 47 | new = XCALLOC(MTYPE_RIPNG_OFFSET_LIST, |
48 | sizeof(struct ripng_offset_list)); | |
5c84b9a5 | 49 | new->ripng = ripng; |
b09956ca | 50 | new->ifname = strdup(ifname); |
26c6be93 | 51 | listnode_add_sort(ripng->offset_list_master, new); |
b09956ca | 52 | |
d62a17ae | 53 | return new; |
a94434b6 | 54 | } |
55 | ||
b09956ca | 56 | void ripng_offset_list_del(struct ripng_offset_list *offset) |
a94434b6 | 57 | { |
5c84b9a5 | 58 | listnode_delete(offset->ripng->offset_list_master, offset); |
6c4c3561 RW |
59 | ripng_offset_list_free(offset); |
60 | } | |
61 | ||
62 | void ripng_offset_list_free(struct ripng_offset_list *offset) | |
63 | { | |
b09956ca RW |
64 | if (OFFSET_LIST_IN_NAME(offset)) |
65 | free(OFFSET_LIST_IN_NAME(offset)); | |
66 | if (OFFSET_LIST_OUT_NAME(offset)) | |
67 | free(OFFSET_LIST_OUT_NAME(offset)); | |
68 | free(offset->ifname); | |
d62a17ae | 69 | XFREE(MTYPE_RIPNG_OFFSET_LIST, offset); |
a94434b6 | 70 | } |
71 | ||
5c84b9a5 RW |
72 | struct ripng_offset_list *ripng_offset_list_lookup(struct ripng *ripng, |
73 | const char *ifname) | |
a94434b6 | 74 | { |
d62a17ae | 75 | struct ripng_offset_list *offset; |
76 | struct listnode *node, *nnode; | |
a94434b6 | 77 | |
26c6be93 RW |
78 | for (ALL_LIST_ELEMENTS(ripng->offset_list_master, node, nnode, |
79 | offset)) { | |
b09956ca | 80 | if (strcmp(offset->ifname, ifname) == 0) |
d62a17ae | 81 | return offset; |
82 | } | |
83 | return NULL; | |
a94434b6 | 84 | } |
85 | ||
a94434b6 | 86 | /* If metric is modifed return 1. */ |
5c84b9a5 RW |
87 | int ripng_offset_list_apply_in(struct ripng *ripng, struct prefix_ipv6 *p, |
88 | struct interface *ifp, uint8_t *metric) | |
a94434b6 | 89 | { |
d62a17ae | 90 | struct ripng_offset_list *offset; |
91 | struct access_list *alist; | |
92 | ||
93 | /* Look up offset-list with interface name. */ | |
5c84b9a5 | 94 | offset = ripng_offset_list_lookup(ripng, ifp->name); |
d62a17ae | 95 | if (offset && OFFSET_LIST_IN_NAME(offset)) { |
96 | alist = access_list_lookup(AFI_IP6, | |
97 | OFFSET_LIST_IN_NAME(offset)); | |
98 | ||
99 | if (alist | |
100 | && access_list_apply(alist, (struct prefix *)p) | |
101 | == FILTER_PERMIT) { | |
102 | *metric += OFFSET_LIST_IN_METRIC(offset); | |
103 | return 1; | |
104 | } | |
105 | return 0; | |
a94434b6 | 106 | } |
d62a17ae | 107 | /* Look up offset-list without interface name. */ |
5c84b9a5 | 108 | offset = ripng_offset_list_lookup(ripng, "*"); |
d62a17ae | 109 | if (offset && OFFSET_LIST_IN_NAME(offset)) { |
110 | alist = access_list_lookup(AFI_IP6, | |
111 | OFFSET_LIST_IN_NAME(offset)); | |
112 | ||
113 | if (alist | |
114 | && access_list_apply(alist, (struct prefix *)p) | |
115 | == FILTER_PERMIT) { | |
116 | *metric += OFFSET_LIST_IN_METRIC(offset); | |
117 | return 1; | |
118 | } | |
119 | return 0; | |
a94434b6 | 120 | } |
d62a17ae | 121 | return 0; |
a94434b6 | 122 | } |
123 | ||
124 | /* If metric is modifed return 1. */ | |
5c84b9a5 RW |
125 | int ripng_offset_list_apply_out(struct ripng *ripng, struct prefix_ipv6 *p, |
126 | struct interface *ifp, uint8_t *metric) | |
a94434b6 | 127 | { |
d62a17ae | 128 | struct ripng_offset_list *offset; |
129 | struct access_list *alist; | |
130 | ||
131 | /* Look up offset-list with interface name. */ | |
5c84b9a5 | 132 | offset = ripng_offset_list_lookup(ripng, ifp->name); |
d62a17ae | 133 | if (offset && OFFSET_LIST_OUT_NAME(offset)) { |
134 | alist = access_list_lookup(AFI_IP6, | |
135 | OFFSET_LIST_OUT_NAME(offset)); | |
136 | ||
137 | if (alist | |
138 | && access_list_apply(alist, (struct prefix *)p) | |
139 | == FILTER_PERMIT) { | |
140 | *metric += OFFSET_LIST_OUT_METRIC(offset); | |
141 | return 1; | |
142 | } | |
143 | return 0; | |
a94434b6 | 144 | } |
d62a17ae | 145 | |
146 | /* Look up offset-list without interface name. */ | |
5c84b9a5 | 147 | offset = ripng_offset_list_lookup(ripng, "*"); |
d62a17ae | 148 | if (offset && OFFSET_LIST_OUT_NAME(offset)) { |
149 | alist = access_list_lookup(AFI_IP6, | |
150 | OFFSET_LIST_OUT_NAME(offset)); | |
151 | ||
152 | if (alist | |
153 | && access_list_apply(alist, (struct prefix *)p) | |
154 | == FILTER_PERMIT) { | |
155 | *metric += OFFSET_LIST_OUT_METRIC(offset); | |
156 | return 1; | |
157 | } | |
158 | return 0; | |
a94434b6 | 159 | } |
d62a17ae | 160 | return 0; |
a94434b6 | 161 | } |
162 | ||
26c6be93 | 163 | int offset_list_cmp(struct ripng_offset_list *o1, struct ripng_offset_list *o2) |
a94434b6 | 164 | { |
b09956ca | 165 | return strcmp(o1->ifname, o2->ifname); |
a94434b6 | 166 | } |