]>
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 DEFINE_MTYPE_STATIC(RIPD
, RIP_OFFSET_LIST
, "RIP offset list")
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(struct rip
*rip
, const char *ifname
)
42 struct rip_offset_list
*offset
;
44 offset
= XCALLOC(MTYPE_RIP_OFFSET_LIST
, sizeof(struct rip_offset_list
));
46 offset
->ifname
= strdup(ifname
);
47 listnode_add_sort(rip
->offset_list_master
, offset
);
52 void offset_list_del(struct rip_offset_list
*offset
)
54 listnode_delete(offset
->rip
->offset_list_master
, offset
);
55 offset_list_free(offset
);
58 void offset_list_free(struct rip_offset_list
*offset
)
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
));
65 XFREE(MTYPE_RIP_OFFSET_LIST
, offset
);
68 struct rip_offset_list
*rip_offset_list_lookup(struct rip
*rip
,
71 struct rip_offset_list
*offset
;
72 struct listnode
*node
, *nnode
;
74 for (ALL_LIST_ELEMENTS(rip
->offset_list_master
, node
, nnode
, offset
)) {
75 if (strcmp(offset
->ifname
, ifname
) == 0)
81 /* If metric is modifed return 1. */
82 int rip_offset_list_apply_in(struct prefix_ipv4
*p
, struct interface
*ifp
,
85 struct rip_interface
*ri
= ifp
->info
;
86 struct rip_offset_list
*offset
;
87 struct access_list
*alist
;
89 /* Look up offset-list with interface name. */
90 offset
= rip_offset_list_lookup(ri
->rip
, ifp
->name
);
91 if (offset
&& OFFSET_LIST_IN_NAME(offset
)) {
92 alist
= access_list_lookup(AFI_IP
, OFFSET_LIST_IN_NAME(offset
));
95 && access_list_apply(alist
, (struct prefix
*)p
)
97 *metric
+= OFFSET_LIST_IN_METRIC(offset
);
102 /* Look up offset-list without interface name. */
103 offset
= rip_offset_list_lookup(ri
->rip
, "*");
104 if (offset
&& OFFSET_LIST_IN_NAME(offset
)) {
105 alist
= access_list_lookup(AFI_IP
, OFFSET_LIST_IN_NAME(offset
));
108 && access_list_apply(alist
, (struct prefix
*)p
)
110 *metric
+= OFFSET_LIST_IN_METRIC(offset
);
118 /* If metric is modifed return 1. */
119 int rip_offset_list_apply_out(struct prefix_ipv4
*p
, struct interface
*ifp
,
122 struct rip_interface
*ri
= ifp
->info
;
123 struct rip_offset_list
*offset
;
124 struct access_list
*alist
;
126 /* Look up offset-list with interface name. */
127 offset
= rip_offset_list_lookup(ri
->rip
, ifp
->name
);
128 if (offset
&& OFFSET_LIST_OUT_NAME(offset
)) {
129 alist
= access_list_lookup(AFI_IP
,
130 OFFSET_LIST_OUT_NAME(offset
));
133 && access_list_apply(alist
, (struct prefix
*)p
)
135 *metric
+= OFFSET_LIST_OUT_METRIC(offset
);
141 /* Look up offset-list without interface name. */
142 offset
= rip_offset_list_lookup(ri
->rip
, "*");
143 if (offset
&& OFFSET_LIST_OUT_NAME(offset
)) {
144 alist
= access_list_lookup(AFI_IP
,
145 OFFSET_LIST_OUT_NAME(offset
));
148 && access_list_apply(alist
, (struct prefix
*)p
)
150 *metric
+= OFFSET_LIST_OUT_METRIC(offset
);
158 int offset_list_cmp(struct rip_offset_list
*o1
, struct rip_offset_list
*o2
)
160 return strcmp(o1
->ifname
, o2
->ifname
);