]>
git.proxmox.com Git - mirror_frr.git/blob - ripd/rip_offset.c
1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Copyright (C) 2000 Kunihiro Ishiguro <kunihiro@zebra.org>
15 #include "ripd/ripd.h"
17 DEFINE_MTYPE_STATIC(RIPD
, RIP_OFFSET_LIST
, "RIP offset list");
19 #define OFFSET_LIST_IN_NAME(O) ((O)->direct[RIP_OFFSET_LIST_IN].alist_name)
20 #define OFFSET_LIST_IN_METRIC(O) ((O)->direct[RIP_OFFSET_LIST_IN].metric)
22 #define OFFSET_LIST_OUT_NAME(O) ((O)->direct[RIP_OFFSET_LIST_OUT].alist_name)
23 #define OFFSET_LIST_OUT_METRIC(O) ((O)->direct[RIP_OFFSET_LIST_OUT].metric)
25 struct rip_offset_list
*rip_offset_list_new(struct rip
*rip
, const char *ifname
)
27 struct rip_offset_list
*offset
;
29 offset
= XCALLOC(MTYPE_RIP_OFFSET_LIST
, sizeof(struct rip_offset_list
));
31 offset
->ifname
= strdup(ifname
);
32 listnode_add_sort(rip
->offset_list_master
, offset
);
37 void offset_list_del(struct rip_offset_list
*offset
)
39 listnode_delete(offset
->rip
->offset_list_master
, offset
);
40 offset_list_free(offset
);
43 void offset_list_free(struct rip_offset_list
*offset
)
45 if (OFFSET_LIST_IN_NAME(offset
))
46 free(OFFSET_LIST_IN_NAME(offset
));
47 if (OFFSET_LIST_OUT_NAME(offset
))
48 free(OFFSET_LIST_OUT_NAME(offset
));
50 XFREE(MTYPE_RIP_OFFSET_LIST
, offset
);
53 struct rip_offset_list
*rip_offset_list_lookup(struct rip
*rip
,
56 struct rip_offset_list
*offset
;
57 struct listnode
*node
, *nnode
;
59 for (ALL_LIST_ELEMENTS(rip
->offset_list_master
, node
, nnode
, offset
)) {
60 if (strcmp(offset
->ifname
, ifname
) == 0)
66 /* If metric is modified return 1. */
67 int rip_offset_list_apply_in(struct prefix_ipv4
*p
, struct interface
*ifp
,
70 struct rip_interface
*ri
= ifp
->info
;
71 struct rip_offset_list
*offset
;
72 struct access_list
*alist
;
74 /* Look up offset-list with interface name. */
75 offset
= rip_offset_list_lookup(ri
->rip
, ifp
->name
);
76 if (offset
&& OFFSET_LIST_IN_NAME(offset
)) {
77 alist
= access_list_lookup(AFI_IP
, OFFSET_LIST_IN_NAME(offset
));
80 && access_list_apply(alist
, (struct prefix
*)p
)
82 *metric
+= OFFSET_LIST_IN_METRIC(offset
);
87 /* Look up offset-list without interface name. */
88 offset
= rip_offset_list_lookup(ri
->rip
, "*");
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
);
103 /* If metric is modified return 1. */
104 int rip_offset_list_apply_out(struct prefix_ipv4
*p
, struct interface
*ifp
,
107 struct rip_interface
*ri
= ifp
->info
;
108 struct rip_offset_list
*offset
;
109 struct access_list
*alist
;
111 /* Look up offset-list with interface name. */
112 offset
= rip_offset_list_lookup(ri
->rip
, ifp
->name
);
113 if (offset
&& OFFSET_LIST_OUT_NAME(offset
)) {
114 alist
= access_list_lookup(AFI_IP
,
115 OFFSET_LIST_OUT_NAME(offset
));
118 && access_list_apply(alist
, (struct prefix
*)p
)
120 *metric
+= OFFSET_LIST_OUT_METRIC(offset
);
126 /* Look up offset-list without interface name. */
127 offset
= rip_offset_list_lookup(ri
->rip
, "*");
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
);
143 int offset_list_cmp(struct rip_offset_list
*o1
, struct rip_offset_list
*o2
)
145 return strcmp(o1
->ifname
, o2
->ifname
);