]> git.proxmox.com Git - mirror_frr.git/blame - ripngd/ripng_offset.c
zebra: Allow ns delete to happen after under/over flow checks
[mirror_frr.git] / ripngd / ripng_offset.c
CommitLineData
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
a94434b6 36static struct list *ripng_offset_list_master;
37
b09956ca
RW
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)
a94434b6 43
b09956ca 44struct ripng_offset_list *ripng_offset_list_new(const char *ifname)
a94434b6 45{
d62a17ae 46 struct ripng_offset_list *new;
a94434b6 47
d62a17ae 48 new = XCALLOC(MTYPE_RIPNG_OFFSET_LIST,
49 sizeof(struct ripng_offset_list));
b09956ca
RW
50 new->ifname = strdup(ifname);
51 listnode_add_sort(ripng_offset_list_master, new);
52
d62a17ae 53 return new;
a94434b6 54}
55
b09956ca 56void ripng_offset_list_del(struct ripng_offset_list *offset)
a94434b6 57{
b09956ca
RW
58 listnode_delete(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);
d62a17ae 64 XFREE(MTYPE_RIPNG_OFFSET_LIST, offset);
a94434b6 65}
66
b09956ca 67struct ripng_offset_list *ripng_offset_list_lookup(const char *ifname)
a94434b6 68{
d62a17ae 69 struct ripng_offset_list *offset;
70 struct listnode *node, *nnode;
a94434b6 71
d62a17ae 72 for (ALL_LIST_ELEMENTS(ripng_offset_list_master, node, nnode, offset)) {
b09956ca 73 if (strcmp(offset->ifname, ifname) == 0)
d62a17ae 74 return offset;
75 }
76 return NULL;
a94434b6 77}
78
a94434b6 79/* If metric is modifed return 1. */
d62a17ae 80int ripng_offset_list_apply_in(struct prefix_ipv6 *p, struct interface *ifp,
d7c0a89a 81 uint8_t *metric)
a94434b6 82{
d62a17ae 83 struct ripng_offset_list *offset;
84 struct access_list *alist;
85
86 /* Look up offset-list with interface name. */
87 offset = ripng_offset_list_lookup(ifp->name);
88 if (offset && OFFSET_LIST_IN_NAME(offset)) {
89 alist = access_list_lookup(AFI_IP6,
90 OFFSET_LIST_IN_NAME(offset));
91
92 if (alist
93 && access_list_apply(alist, (struct prefix *)p)
94 == FILTER_PERMIT) {
95 *metric += OFFSET_LIST_IN_METRIC(offset);
96 return 1;
97 }
98 return 0;
a94434b6 99 }
d62a17ae 100 /* Look up offset-list without interface name. */
b09956ca 101 offset = ripng_offset_list_lookup("*");
d62a17ae 102 if (offset && OFFSET_LIST_IN_NAME(offset)) {
103 alist = access_list_lookup(AFI_IP6,
104 OFFSET_LIST_IN_NAME(offset));
105
106 if (alist
107 && access_list_apply(alist, (struct prefix *)p)
108 == FILTER_PERMIT) {
109 *metric += OFFSET_LIST_IN_METRIC(offset);
110 return 1;
111 }
112 return 0;
a94434b6 113 }
d62a17ae 114 return 0;
a94434b6 115}
116
117/* If metric is modifed return 1. */
d62a17ae 118int ripng_offset_list_apply_out(struct prefix_ipv6 *p, struct interface *ifp,
d7c0a89a 119 uint8_t *metric)
a94434b6 120{
d62a17ae 121 struct ripng_offset_list *offset;
122 struct access_list *alist;
123
124 /* Look up offset-list with interface name. */
125 offset = ripng_offset_list_lookup(ifp->name);
126 if (offset && OFFSET_LIST_OUT_NAME(offset)) {
127 alist = access_list_lookup(AFI_IP6,
128 OFFSET_LIST_OUT_NAME(offset));
129
130 if (alist
131 && access_list_apply(alist, (struct prefix *)p)
132 == FILTER_PERMIT) {
133 *metric += OFFSET_LIST_OUT_METRIC(offset);
134 return 1;
135 }
136 return 0;
a94434b6 137 }
d62a17ae 138
139 /* Look up offset-list without interface name. */
b09956ca 140 offset = ripng_offset_list_lookup("*");
d62a17ae 141 if (offset && OFFSET_LIST_OUT_NAME(offset)) {
142 alist = access_list_lookup(AFI_IP6,
143 OFFSET_LIST_OUT_NAME(offset));
144
145 if (alist
146 && access_list_apply(alist, (struct prefix *)p)
147 == FILTER_PERMIT) {
148 *metric += OFFSET_LIST_OUT_METRIC(offset);
149 return 1;
150 }
151 return 0;
a94434b6 152 }
d62a17ae 153 return 0;
a94434b6 154}
155
d62a17ae 156static int offset_list_cmp(struct ripng_offset_list *o1,
157 struct ripng_offset_list *o2)
a94434b6 158{
b09956ca 159 return strcmp(o1->ifname, o2->ifname);
a94434b6 160}
161
d62a17ae 162void ripng_offset_init(void)
a94434b6 163{
d62a17ae 164 ripng_offset_list_master = list_new();
165 ripng_offset_list_master->cmp =
166 (int (*)(void *, void *))offset_list_cmp;
b09956ca 167 ripng_offset_list_master->del = (void (*)(void *))ripng_offset_list_del;
a94434b6 168}
169
d62a17ae 170void ripng_offset_clean(void)
a94434b6 171{
6a154c88 172 list_delete(&ripng_offset_list_master);
a94434b6 173
d62a17ae 174 ripng_offset_list_master = list_new();
175 ripng_offset_list_master->cmp =
176 (int (*)(void *, void *))offset_list_cmp;
b09956ca 177 ripng_offset_list_master->del = (void (*)(void *))ripng_offset_list_del;
a94434b6 178}