]>
git.proxmox.com Git - mirror_frr.git/blob - ripd/rip_offset.c
2 * Copyright (C) 2000 Kunihiro Ishiguro <kunihiro@zebra.org>
4 * This file is part of GNU Zebra.
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
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.
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
30 #include "ripd/ripd.h"
32 static struct list
*rip_offset_list_master
;
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)
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)
40 struct rip_offset_list
*rip_offset_list_new(const char *ifname
)
42 struct rip_offset_list
*offset
;
44 offset
= XCALLOC(MTYPE_RIP_OFFSET_LIST
, sizeof(struct rip_offset_list
));
45 offset
->ifname
= strdup(ifname
);
46 listnode_add_sort(rip_offset_list_master
, offset
);
51 void offset_list_del(struct rip_offset_list
*offset
)
53 listnode_delete(rip_offset_list_master
, offset
);
54 if (OFFSET_LIST_IN_NAME(offset
))
55 free(OFFSET_LIST_IN_NAME(offset
));
56 if (OFFSET_LIST_OUT_NAME(offset
))
57 free(OFFSET_LIST_OUT_NAME(offset
));
59 XFREE(MTYPE_RIP_OFFSET_LIST
, offset
);
62 struct rip_offset_list
*rip_offset_list_lookup(const char *ifname
)
64 struct rip_offset_list
*offset
;
65 struct listnode
*node
, *nnode
;
67 for (ALL_LIST_ELEMENTS(rip_offset_list_master
, node
, nnode
, offset
)) {
68 if (strcmp(offset
->ifname
, ifname
) == 0)
74 /* If metric is modifed return 1. */
75 int rip_offset_list_apply_in(struct prefix_ipv4
*p
, struct interface
*ifp
,
78 struct rip_offset_list
*offset
;
79 struct access_list
*alist
;
81 /* Look up offset-list with interface name. */
82 offset
= rip_offset_list_lookup(ifp
->name
);
83 if (offset
&& OFFSET_LIST_IN_NAME(offset
)) {
84 alist
= access_list_lookup(AFI_IP
, OFFSET_LIST_IN_NAME(offset
));
87 && access_list_apply(alist
, (struct prefix
*)p
)
89 *metric
+= OFFSET_LIST_IN_METRIC(offset
);
94 /* Look up offset-list without interface name. */
95 offset
= rip_offset_list_lookup("*");
96 if (offset
&& OFFSET_LIST_IN_NAME(offset
)) {
97 alist
= access_list_lookup(AFI_IP
, OFFSET_LIST_IN_NAME(offset
));
100 && access_list_apply(alist
, (struct prefix
*)p
)
102 *metric
+= OFFSET_LIST_IN_METRIC(offset
);
110 /* If metric is modifed return 1. */
111 int rip_offset_list_apply_out(struct prefix_ipv4
*p
, struct interface
*ifp
,
114 struct rip_offset_list
*offset
;
115 struct access_list
*alist
;
117 /* Look up offset-list with interface name. */
118 offset
= rip_offset_list_lookup(ifp
->name
);
119 if (offset
&& OFFSET_LIST_OUT_NAME(offset
)) {
120 alist
= access_list_lookup(AFI_IP
,
121 OFFSET_LIST_OUT_NAME(offset
));
124 && access_list_apply(alist
, (struct prefix
*)p
)
126 *metric
+= OFFSET_LIST_OUT_METRIC(offset
);
132 /* Look up offset-list without interface name. */
133 offset
= rip_offset_list_lookup("*");
134 if (offset
&& OFFSET_LIST_OUT_NAME(offset
)) {
135 alist
= access_list_lookup(AFI_IP
,
136 OFFSET_LIST_OUT_NAME(offset
));
139 && access_list_apply(alist
, (struct prefix
*)p
)
141 *metric
+= OFFSET_LIST_OUT_METRIC(offset
);
149 static int offset_list_cmp(struct rip_offset_list
*o1
,
150 struct rip_offset_list
*o2
)
152 return strcmp(o1
->ifname
, o2
->ifname
);
155 void rip_offset_init(void)
157 rip_offset_list_master
= list_new();
158 rip_offset_list_master
->cmp
= (int (*)(void *, void *))offset_list_cmp
;
159 rip_offset_list_master
->del
= (void (*)(void *))offset_list_del
;
162 void rip_offset_clean(void)
164 list_delete(&rip_offset_list_master
);
166 rip_offset_list_master
= list_new();
167 rip_offset_list_master
->cmp
= (int (*)(void *, void *))offset_list_cmp
;
168 rip_offset_list_master
->del
= (void (*)(void *))offset_list_del
;