]>
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 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)
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)
38 struct rip_offset_list
*rip_offset_list_new(struct rip
*rip
, const char *ifname
)
40 struct rip_offset_list
*offset
;
42 offset
= XCALLOC(MTYPE_RIP_OFFSET_LIST
, sizeof(struct rip_offset_list
));
44 offset
->ifname
= strdup(ifname
);
45 listnode_add_sort(rip
->offset_list_master
, offset
);
50 void offset_list_del(struct rip_offset_list
*offset
)
52 listnode_delete(offset
->rip
->offset_list_master
, offset
);
53 offset_list_free(offset
);
56 void offset_list_free(struct rip_offset_list
*offset
)
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
));
63 XFREE(MTYPE_RIP_OFFSET_LIST
, offset
);
66 struct rip_offset_list
*rip_offset_list_lookup(struct rip
*rip
,
69 struct rip_offset_list
*offset
;
70 struct listnode
*node
, *nnode
;
72 for (ALL_LIST_ELEMENTS(rip
->offset_list_master
, node
, nnode
, offset
)) {
73 if (strcmp(offset
->ifname
, ifname
) == 0)
79 /* If metric is modifed return 1. */
80 int rip_offset_list_apply_in(struct prefix_ipv4
*p
, struct interface
*ifp
,
83 struct rip_interface
*ri
= ifp
->info
;
84 struct rip_offset_list
*offset
;
85 struct access_list
*alist
;
87 /* Look up offset-list with interface name. */
88 offset
= rip_offset_list_lookup(ri
->rip
, ifp
->name
);
89 if (offset
&& OFFSET_LIST_IN_NAME(offset
)) {
90 alist
= access_list_lookup(AFI_IP
, OFFSET_LIST_IN_NAME(offset
));
93 && access_list_apply(alist
, (struct prefix
*)p
)
95 *metric
+= OFFSET_LIST_IN_METRIC(offset
);
100 /* Look up offset-list without interface name. */
101 offset
= rip_offset_list_lookup(ri
->rip
, "*");
102 if (offset
&& OFFSET_LIST_IN_NAME(offset
)) {
103 alist
= access_list_lookup(AFI_IP
, OFFSET_LIST_IN_NAME(offset
));
106 && access_list_apply(alist
, (struct prefix
*)p
)
108 *metric
+= OFFSET_LIST_IN_METRIC(offset
);
116 /* If metric is modifed return 1. */
117 int rip_offset_list_apply_out(struct prefix_ipv4
*p
, struct interface
*ifp
,
120 struct rip_interface
*ri
= ifp
->info
;
121 struct rip_offset_list
*offset
;
122 struct access_list
*alist
;
124 /* Look up offset-list with interface name. */
125 offset
= rip_offset_list_lookup(ri
->rip
, ifp
->name
);
126 if (offset
&& OFFSET_LIST_OUT_NAME(offset
)) {
127 alist
= access_list_lookup(AFI_IP
,
128 OFFSET_LIST_OUT_NAME(offset
));
131 && access_list_apply(alist
, (struct prefix
*)p
)
133 *metric
+= OFFSET_LIST_OUT_METRIC(offset
);
139 /* Look up offset-list without interface name. */
140 offset
= rip_offset_list_lookup(ri
->rip
, "*");
141 if (offset
&& OFFSET_LIST_OUT_NAME(offset
)) {
142 alist
= access_list_lookup(AFI_IP
,
143 OFFSET_LIST_OUT_NAME(offset
));
146 && access_list_apply(alist
, (struct prefix
*)p
)
148 *metric
+= OFFSET_LIST_OUT_METRIC(offset
);
156 int offset_list_cmp(struct rip_offset_list
*o1
, struct rip_offset_list
*o2
)
158 return strcmp(o1
->ifname
, o2
->ifname
);