]> git.proxmox.com Git - mirror_frr.git/blame - ripd/rip_offset.c
Merge pull request #5197 from SumitAgarwal123/BFD_ADMIN_DOWN
[mirror_frr.git] / ripd / rip_offset.c
CommitLineData
718e3744 1/* RIP 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
718e3744 19 */
20
21#include <zebra.h>
22
23#include "if.h"
24#include "prefix.h"
25#include "filter.h"
26#include "command.h"
27#include "linklist.h"
28#include "memory.h"
29
dc63bfd4 30#include "ripd/ripd.h"
31
814a2585
DL
32DEFINE_MTYPE_STATIC(RIPD, RIP_OFFSET_LIST, "RIP offset list")
33
8c942f65
RW
34#define OFFSET_LIST_IN_NAME(O) ((O)->direct[RIP_OFFSET_LIST_IN].alist_name)
35#define OFFSET_LIST_IN_METRIC(O) ((O)->direct[RIP_OFFSET_LIST_IN].metric)
718e3744 36
8c942f65
RW
37#define OFFSET_LIST_OUT_NAME(O) ((O)->direct[RIP_OFFSET_LIST_OUT].alist_name)
38#define OFFSET_LIST_OUT_METRIC(O) ((O)->direct[RIP_OFFSET_LIST_OUT].metric)
718e3744 39
045c5389 40struct rip_offset_list *rip_offset_list_new(struct rip *rip, const char *ifname)
718e3744 41{
d62a17ae 42 struct rip_offset_list *offset;
43
8c942f65 44 offset = XCALLOC(MTYPE_RIP_OFFSET_LIST, sizeof(struct rip_offset_list));
045c5389 45 offset->rip = rip;
8c942f65 46 offset->ifname = strdup(ifname);
3f21c8c4 47 listnode_add_sort(rip->offset_list_master, offset);
d62a17ae 48
49 return offset;
718e3744 50}
51
8c942f65 52void offset_list_del(struct rip_offset_list *offset)
718e3744 53{
045c5389 54 listnode_delete(offset->rip->offset_list_master, offset);
6c4c3561
RW
55 offset_list_free(offset);
56}
57
58void offset_list_free(struct rip_offset_list *offset)
59{
8c942f65
RW
60 if (OFFSET_LIST_IN_NAME(offset))
61 free(OFFSET_LIST_IN_NAME(offset));
62 if (OFFSET_LIST_OUT_NAME(offset))
63 free(OFFSET_LIST_OUT_NAME(offset));
64 free(offset->ifname);
65 XFREE(MTYPE_RIP_OFFSET_LIST, offset);
718e3744 66}
67
045c5389
RW
68struct rip_offset_list *rip_offset_list_lookup(struct rip *rip,
69 const char *ifname)
718e3744 70{
d62a17ae 71 struct rip_offset_list *offset;
8c942f65 72 struct listnode *node, *nnode;
d62a17ae 73
3f21c8c4 74 for (ALL_LIST_ELEMENTS(rip->offset_list_master, node, nnode, offset)) {
8c942f65
RW
75 if (strcmp(offset->ifname, ifname) == 0)
76 return offset;
d62a17ae 77 }
8c942f65 78 return NULL;
718e3744 79}
80
718e3744 81/* If metric is modifed return 1. */
d62a17ae 82int rip_offset_list_apply_in(struct prefix_ipv4 *p, struct interface *ifp,
d7c0a89a 83 uint32_t *metric)
718e3744 84{
045c5389 85 struct rip_interface *ri = ifp->info;
d62a17ae 86 struct rip_offset_list *offset;
87 struct access_list *alist;
88
89 /* Look up offset-list with interface name. */
045c5389 90 offset = rip_offset_list_lookup(ri->rip, ifp->name);
d62a17ae 91 if (offset && OFFSET_LIST_IN_NAME(offset)) {
92 alist = access_list_lookup(AFI_IP, 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;
718e3744 101 }
d62a17ae 102 /* Look up offset-list without interface name. */
045c5389 103 offset = rip_offset_list_lookup(ri->rip, "*");
d62a17ae 104 if (offset && OFFSET_LIST_IN_NAME(offset)) {
105 alist = access_list_lookup(AFI_IP, OFFSET_LIST_IN_NAME(offset));
106
107 if (alist
108 && access_list_apply(alist, (struct prefix *)p)
109 == FILTER_PERMIT) {
110 *metric += OFFSET_LIST_IN_METRIC(offset);
111 return 1;
112 }
113 return 0;
718e3744 114 }
d62a17ae 115 return 0;
718e3744 116}
117
118/* If metric is modifed return 1. */
d62a17ae 119int rip_offset_list_apply_out(struct prefix_ipv4 *p, struct interface *ifp,
d7c0a89a 120 uint32_t *metric)
718e3744 121{
045c5389 122 struct rip_interface *ri = ifp->info;
d62a17ae 123 struct rip_offset_list *offset;
124 struct access_list *alist;
125
126 /* Look up offset-list with interface name. */
045c5389 127 offset = rip_offset_list_lookup(ri->rip, ifp->name);
d62a17ae 128 if (offset && OFFSET_LIST_OUT_NAME(offset)) {
129 alist = access_list_lookup(AFI_IP,
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;
718e3744 139 }
d62a17ae 140
141 /* Look up offset-list without interface name. */
045c5389 142 offset = rip_offset_list_lookup(ri->rip, "*");
d62a17ae 143 if (offset && OFFSET_LIST_OUT_NAME(offset)) {
144 alist = access_list_lookup(AFI_IP,
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;
718e3744 154 }
d62a17ae 155 return 0;
718e3744 156}
157
3f21c8c4 158int offset_list_cmp(struct rip_offset_list *o1, struct rip_offset_list *o2)
718e3744 159{
8c942f65 160 return strcmp(o1->ifname, o2->ifname);
718e3744 161}