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