]>
Commit | Line | Data |
---|---|---|
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 | ||
8c942f65 RW |
32 | #define OFFSET_LIST_IN_NAME(O) ((O)->direct[RIP_OFFSET_LIST_IN].alist_name) |
33 | #define OFFSET_LIST_IN_METRIC(O) ((O)->direct[RIP_OFFSET_LIST_IN].metric) | |
718e3744 | 34 | |
8c942f65 RW |
35 | #define OFFSET_LIST_OUT_NAME(O) ((O)->direct[RIP_OFFSET_LIST_OUT].alist_name) |
36 | #define OFFSET_LIST_OUT_METRIC(O) ((O)->direct[RIP_OFFSET_LIST_OUT].metric) | |
718e3744 | 37 | |
045c5389 | 38 | struct rip_offset_list *rip_offset_list_new(struct rip *rip, const char *ifname) |
718e3744 | 39 | { |
d62a17ae | 40 | struct rip_offset_list *offset; |
41 | ||
8c942f65 | 42 | offset = XCALLOC(MTYPE_RIP_OFFSET_LIST, sizeof(struct rip_offset_list)); |
045c5389 | 43 | offset->rip = rip; |
8c942f65 | 44 | offset->ifname = strdup(ifname); |
3f21c8c4 | 45 | listnode_add_sort(rip->offset_list_master, offset); |
d62a17ae | 46 | |
47 | return offset; | |
718e3744 | 48 | } |
49 | ||
8c942f65 | 50 | void offset_list_del(struct rip_offset_list *offset) |
718e3744 | 51 | { |
045c5389 | 52 | listnode_delete(offset->rip->offset_list_master, offset); |
6c4c3561 RW |
53 | offset_list_free(offset); |
54 | } | |
55 | ||
56 | void offset_list_free(struct rip_offset_list *offset) | |
57 | { | |
8c942f65 RW |
58 | if (OFFSET_LIST_IN_NAME(offset)) |
59 | free(OFFSET_LIST_IN_NAME(offset)); | |
60 | if (OFFSET_LIST_OUT_NAME(offset)) | |
61 | free(OFFSET_LIST_OUT_NAME(offset)); | |
62 | free(offset->ifname); | |
63 | XFREE(MTYPE_RIP_OFFSET_LIST, offset); | |
718e3744 | 64 | } |
65 | ||
045c5389 RW |
66 | struct rip_offset_list *rip_offset_list_lookup(struct rip *rip, |
67 | const char *ifname) | |
718e3744 | 68 | { |
d62a17ae | 69 | struct rip_offset_list *offset; |
8c942f65 | 70 | struct listnode *node, *nnode; |
d62a17ae | 71 | |
3f21c8c4 | 72 | for (ALL_LIST_ELEMENTS(rip->offset_list_master, node, nnode, offset)) { |
8c942f65 RW |
73 | if (strcmp(offset->ifname, ifname) == 0) |
74 | return offset; | |
d62a17ae | 75 | } |
8c942f65 | 76 | return NULL; |
718e3744 | 77 | } |
78 | ||
718e3744 | 79 | /* If metric is modifed return 1. */ |
d62a17ae | 80 | int rip_offset_list_apply_in(struct prefix_ipv4 *p, struct interface *ifp, |
d7c0a89a | 81 | uint32_t *metric) |
718e3744 | 82 | { |
045c5389 | 83 | struct rip_interface *ri = ifp->info; |
d62a17ae | 84 | struct rip_offset_list *offset; |
85 | struct access_list *alist; | |
86 | ||
87 | /* Look up offset-list with interface name. */ | |
045c5389 | 88 | offset = rip_offset_list_lookup(ri->rip, ifp->name); |
d62a17ae | 89 | if (offset && OFFSET_LIST_IN_NAME(offset)) { |
90 | alist = access_list_lookup(AFI_IP, 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; | |
718e3744 | 99 | } |
d62a17ae | 100 | /* Look up offset-list without interface name. */ |
045c5389 | 101 | offset = rip_offset_list_lookup(ri->rip, "*"); |
d62a17ae | 102 | if (offset && OFFSET_LIST_IN_NAME(offset)) { |
103 | alist = access_list_lookup(AFI_IP, OFFSET_LIST_IN_NAME(offset)); | |
104 | ||
105 | if (alist | |
106 | && access_list_apply(alist, (struct prefix *)p) | |
107 | == FILTER_PERMIT) { | |
108 | *metric += OFFSET_LIST_IN_METRIC(offset); | |
109 | return 1; | |
110 | } | |
111 | return 0; | |
718e3744 | 112 | } |
d62a17ae | 113 | return 0; |
718e3744 | 114 | } |
115 | ||
116 | /* If metric is modifed return 1. */ | |
d62a17ae | 117 | int rip_offset_list_apply_out(struct prefix_ipv4 *p, struct interface *ifp, |
d7c0a89a | 118 | uint32_t *metric) |
718e3744 | 119 | { |
045c5389 | 120 | struct rip_interface *ri = ifp->info; |
d62a17ae | 121 | struct rip_offset_list *offset; |
122 | struct access_list *alist; | |
123 | ||
124 | /* Look up offset-list with interface name. */ | |
045c5389 | 125 | offset = rip_offset_list_lookup(ri->rip, ifp->name); |
d62a17ae | 126 | if (offset && OFFSET_LIST_OUT_NAME(offset)) { |
127 | alist = access_list_lookup(AFI_IP, | |
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; | |
718e3744 | 137 | } |
d62a17ae | 138 | |
139 | /* Look up offset-list without interface name. */ | |
045c5389 | 140 | offset = rip_offset_list_lookup(ri->rip, "*"); |
d62a17ae | 141 | if (offset && OFFSET_LIST_OUT_NAME(offset)) { |
142 | alist = access_list_lookup(AFI_IP, | |
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; | |
718e3744 | 152 | } |
d62a17ae | 153 | return 0; |
718e3744 | 154 | } |
155 | ||
3f21c8c4 | 156 | int offset_list_cmp(struct rip_offset_list *o1, struct rip_offset_list *o2) |
718e3744 | 157 | { |
8c942f65 | 158 | return strcmp(o1->ifname, o2->ifname); |
718e3744 | 159 | } |