]>
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 if (OFFSET_LIST_IN_NAME(offset
))
54 free(OFFSET_LIST_IN_NAME(offset
));
55 if (OFFSET_LIST_OUT_NAME(offset
))
56 free(OFFSET_LIST_OUT_NAME(offset
));
58 XFREE(MTYPE_RIP_OFFSET_LIST
, offset
);
61 struct rip_offset_list
*rip_offset_list_lookup(struct rip
*rip
,
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_interface
*ri
= ifp
->info
;
79 struct rip_offset_list
*offset
;
80 struct access_list
*alist
;
82 /* Look up offset-list with interface name. */
83 offset
= rip_offset_list_lookup(ri
->rip
, ifp
->name
);
84 if (offset
&& OFFSET_LIST_IN_NAME(offset
)) {
85 alist
= access_list_lookup(AFI_IP
, OFFSET_LIST_IN_NAME(offset
));
88 && access_list_apply(alist
, (struct prefix
*)p
)
90 *metric
+= OFFSET_LIST_IN_METRIC(offset
);
95 /* Look up offset-list without interface name. */
96 offset
= rip_offset_list_lookup(ri
->rip
, "*");
97 if (offset
&& OFFSET_LIST_IN_NAME(offset
)) {
98 alist
= access_list_lookup(AFI_IP
, OFFSET_LIST_IN_NAME(offset
));
101 && access_list_apply(alist
, (struct prefix
*)p
)
103 *metric
+= OFFSET_LIST_IN_METRIC(offset
);
111 /* If metric is modifed return 1. */
112 int rip_offset_list_apply_out(struct prefix_ipv4
*p
, struct interface
*ifp
,
115 struct rip_interface
*ri
= ifp
->info
;
116 struct rip_offset_list
*offset
;
117 struct access_list
*alist
;
119 /* Look up offset-list with interface name. */
120 offset
= rip_offset_list_lookup(ri
->rip
, ifp
->name
);
121 if (offset
&& OFFSET_LIST_OUT_NAME(offset
)) {
122 alist
= access_list_lookup(AFI_IP
,
123 OFFSET_LIST_OUT_NAME(offset
));
126 && access_list_apply(alist
, (struct prefix
*)p
)
128 *metric
+= OFFSET_LIST_OUT_METRIC(offset
);
134 /* Look up offset-list without interface name. */
135 offset
= rip_offset_list_lookup(ri
->rip
, "*");
136 if (offset
&& OFFSET_LIST_OUT_NAME(offset
)) {
137 alist
= access_list_lookup(AFI_IP
,
138 OFFSET_LIST_OUT_NAME(offset
));
141 && access_list_apply(alist
, (struct prefix
*)p
)
143 *metric
+= OFFSET_LIST_OUT_METRIC(offset
);
151 int offset_list_cmp(struct rip_offset_list
*o1
, struct rip_offset_list
*o2
)
153 return strcmp(o1
->ifname
, o2
->ifname
);