18 #include <netlink-local.h>
19 #include <netlink/netlink.h>
20 #include <netlink/utils.h>
21 #include <netlink/route/rtnl.h>
22 #include <netlink/route/route.h>
29 struct rtnl_nexthop *rtnl_route_nh_alloc(
void)
31 struct rtnl_nexthop *nh;
33 nh = calloc(1,
sizeof(*nh));
39 nl_init_list_head(&nh->rtnh_list);
44 struct rtnl_nexthop *rtnl_route_nh_clone(
struct rtnl_nexthop *src)
46 struct rtnl_nexthop *nh;
48 nh = rtnl_route_nh_alloc();
52 nh->rtnh_flags = src->rtnh_flags;
53 nh->rtnh_flag_mask = src->rtnh_flag_mask;
54 nh->rtnh_weight = src->rtnh_weight;
55 nh->rtnh_ifindex = src->rtnh_ifindex;
56 nh->rtnh_mask = src->rtnh_mask;
58 if (src->rtnh_gateway) {
60 if (!nh->rtnh_gateway) {
69 void rtnl_route_nh_free(
struct rtnl_nexthop *nh)
71 nl_addr_put(nh->rtnh_gateway);
81 void rtnl_route_nh_set_weight(
struct rtnl_nexthop *nh,
int weight)
83 nh->rtnh_weight = weight;
84 nh->rtnh_mask |= NEXTHOP_HAS_WEIGHT;
87 int rtnl_route_nh_get_weight(
struct rtnl_nexthop *nh)
89 if (nh->rtnh_mask & NEXTHOP_HAS_WEIGHT)
90 return nh->rtnh_weight;
95 void rtnl_route_nh_set_ifindex(
struct rtnl_nexthop *nh,
int ifindex)
97 nh->rtnh_ifindex = ifindex;
98 nh->rtnh_mask |= NEXTHOP_HAS_IFINDEX;
101 int rtnl_route_nh_get_ifindex(
struct rtnl_nexthop *nh)
103 if (nh->rtnh_mask & NEXTHOP_HAS_IFINDEX)
104 return nh->rtnh_ifindex;
109 void rtnl_route_nh_set_gateway(
struct rtnl_nexthop *nh,
struct nl_addr *addr)
111 struct nl_addr *old = nh->rtnh_gateway;
113 nh->rtnh_gateway = nl_addr_get(addr);
117 nh->rtnh_mask |= NEXTHOP_HAS_GATEWAY;
120 struct nl_addr *rtnl_route_nh_get_gateway(
struct rtnl_nexthop *nh)
122 if (nh->rtnh_mask & NEXTHOP_HAS_GATEWAY)
123 return nh->rtnh_gateway;
128 void rtnl_route_nh_set_flags(
struct rtnl_nexthop *nh,
unsigned int flags)
130 nh->rtnh_flag_mask |= flags;
131 nh->rtnh_flags |= flags;
132 nh->rtnh_mask |= NEXTHOP_HAS_FLAGS;
135 void rtnl_route_nh_unset_flags(
struct rtnl_nexthop *nh,
unsigned int flags)
137 nh->rtnh_flag_mask |= flags;
138 nh->rtnh_flags &= ~flags;
139 nh->rtnh_mask |= NEXTHOP_HAS_FLAGS;
142 unsigned int rtnl_route_nh_get_flags(
struct rtnl_nexthop *nh)
144 if (nh->rtnh_mask & NEXTHOP_HAS_FLAGS)
145 return nh->rtnh_flags;
struct nl_addr * nl_addr_clone(struct nl_addr *addr)
Clone existing abstract address object.