Lines Matching refs:nh
44 struct rtnl_nexthop *nh; in rtnl_route_nh_alloc() local
46 nh = calloc(1, sizeof(*nh)); in rtnl_route_nh_alloc()
47 if (!nh) in rtnl_route_nh_alloc()
50 nl_init_list_head(&nh->rtnh_list); in rtnl_route_nh_alloc()
52 return nh; in rtnl_route_nh_alloc()
57 struct rtnl_nexthop *nh; in rtnl_route_nh_clone() local
59 nh = rtnl_route_nh_alloc(); in rtnl_route_nh_clone()
60 if (!nh) in rtnl_route_nh_clone()
63 nh->rtnh_flags = src->rtnh_flags; in rtnl_route_nh_clone()
64 nh->rtnh_flag_mask = src->rtnh_flag_mask; in rtnl_route_nh_clone()
65 nh->rtnh_weight = src->rtnh_weight; in rtnl_route_nh_clone()
66 nh->rtnh_ifindex = src->rtnh_ifindex; in rtnl_route_nh_clone()
67 nh->ce_mask = src->ce_mask; in rtnl_route_nh_clone()
70 nh->rtnh_gateway = nl_addr_clone(src->rtnh_gateway); in rtnl_route_nh_clone()
71 if (!nh->rtnh_gateway) { in rtnl_route_nh_clone()
72 free(nh); in rtnl_route_nh_clone()
78 nh->rtnh_newdst = nl_addr_clone(src->rtnh_newdst); in rtnl_route_nh_clone()
79 if (!nh->rtnh_newdst) { in rtnl_route_nh_clone()
80 nl_addr_put(nh->rtnh_gateway); in rtnl_route_nh_clone()
81 free(nh); in rtnl_route_nh_clone()
87 nh->rtnh_via = nl_addr_clone(src->rtnh_via); in rtnl_route_nh_clone()
88 if (!nh->rtnh_via) { in rtnl_route_nh_clone()
89 nl_addr_put(nh->rtnh_gateway); in rtnl_route_nh_clone()
90 nl_addr_put(nh->rtnh_newdst); in rtnl_route_nh_clone()
91 free(nh); in rtnl_route_nh_clone()
96 return nh; in rtnl_route_nh_clone()
99 void rtnl_route_nh_free(struct rtnl_nexthop *nh) in rtnl_route_nh_free() argument
101 nl_addr_put(nh->rtnh_gateway); in rtnl_route_nh_free()
102 nl_addr_put(nh->rtnh_newdst); in rtnl_route_nh_free()
103 nl_addr_put(nh->rtnh_via); in rtnl_route_nh_free()
104 if (nh->rtnh_encap) { in rtnl_route_nh_free()
105 if (nh->rtnh_encap->ops && nh->rtnh_encap->ops->destructor) in rtnl_route_nh_free()
106 nh->rtnh_encap->ops->destructor(nh->rtnh_encap->priv); in rtnl_route_nh_free()
107 free(nh->rtnh_encap->priv); in rtnl_route_nh_free()
108 free(nh->rtnh_encap); in rtnl_route_nh_free()
110 free(nh); in rtnl_route_nh_free()
145 static void nh_dump_line(struct rtnl_nexthop *nh, struct nl_dump_params *dp) in nh_dump_line() argument
152 if (nh->ce_mask & NH_ATTR_ENCAP) in nh_dump_line()
153 nh_encap_dump(nh->rtnh_encap, dp); in nh_dump_line()
155 if (nh->ce_mask & NH_ATTR_NEWDST) in nh_dump_line()
157 nl_addr2str(nh->rtnh_newdst, buf, sizeof(buf))); in nh_dump_line()
161 if (nh->ce_mask & NH_ATTR_VIA) in nh_dump_line()
163 nl_addr2str(nh->rtnh_via, buf, sizeof(buf))); in nh_dump_line()
165 if (nh->ce_mask & NH_ATTR_GATEWAY) in nh_dump_line()
166 nl_dump(dp, " %s", nl_addr2str(nh->rtnh_gateway, in nh_dump_line()
169 if(nh->ce_mask & NH_ATTR_IFINDEX) { in nh_dump_line()
173 nh->rtnh_ifindex, in nh_dump_line()
176 nl_dump(dp, " dev %d", nh->rtnh_ifindex); in nh_dump_line()
185 static void nh_dump_details(struct rtnl_nexthop *nh, struct nl_dump_params *dp) in nh_dump_details() argument
194 if (nh->ce_mask & NH_ATTR_ENCAP) in nh_dump_details()
195 nh_encap_dump(nh->rtnh_encap, dp); in nh_dump_details()
197 if (nh->ce_mask & NH_ATTR_NEWDST) in nh_dump_details()
199 nl_addr2str(nh->rtnh_newdst, buf, sizeof(buf))); in nh_dump_details()
201 if (nh->ce_mask & NH_ATTR_VIA) in nh_dump_details()
203 nl_addr2str(nh->rtnh_via, buf, sizeof(buf))); in nh_dump_details()
205 if (nh->ce_mask & NH_ATTR_GATEWAY) in nh_dump_details()
206 nl_dump(dp, " via %s", nl_addr2str(nh->rtnh_gateway, in nh_dump_details()
209 if(nh->ce_mask & NH_ATTR_IFINDEX) { in nh_dump_details()
213 nh->rtnh_ifindex, in nh_dump_details()
216 nl_dump(dp, " dev %d", nh->rtnh_ifindex); in nh_dump_details()
219 if (nh->ce_mask & NH_ATTR_WEIGHT) in nh_dump_details()
220 nl_dump(dp, " weight %u", nh->rtnh_weight); in nh_dump_details()
222 if (nh->ce_mask & NH_ATTR_REALMS) in nh_dump_details()
224 RTNL_REALM_FROM(nh->rtnh_realms), in nh_dump_details()
225 RTNL_REALM_TO(nh->rtnh_realms)); in nh_dump_details()
227 if (nh->ce_mask & NH_ATTR_FLAGS) in nh_dump_details()
228 nl_dump(dp, " <%s>", rtnl_route_nh_flags2str(nh->rtnh_flags, in nh_dump_details()
235 void rtnl_route_nh_dump(struct rtnl_nexthop *nh, struct nl_dump_params *dp) in rtnl_route_nh_dump() argument
239 nh_dump_line(nh, dp); in rtnl_route_nh_dump()
245 nh_dump_details(nh, dp); in rtnl_route_nh_dump()
253 void nh_set_encap(struct rtnl_nexthop *nh, struct rtnl_nh_encap *rtnh_encap) in nh_set_encap() argument
255 if (nh->rtnh_encap) { in nh_set_encap()
256 if (nh->rtnh_encap->ops && nh->rtnh_encap->ops->destructor) in nh_set_encap()
257 nh->rtnh_encap->ops->destructor(nh->rtnh_encap->priv); in nh_set_encap()
258 free(nh->rtnh_encap->priv); in nh_set_encap()
259 free(nh->rtnh_encap); in nh_set_encap()
263 nh->rtnh_encap = rtnh_encap; in nh_set_encap()
264 nh->ce_mask |= NH_ATTR_ENCAP; in nh_set_encap()
266 nh->rtnh_encap = NULL; in nh_set_encap()
267 nh->ce_mask &= ~NH_ATTR_ENCAP; in nh_set_encap()
276 void rtnl_route_nh_set_weight(struct rtnl_nexthop *nh, uint8_t weight) in rtnl_route_nh_set_weight() argument
278 nh->rtnh_weight = weight; in rtnl_route_nh_set_weight()
279 nh->ce_mask |= NH_ATTR_WEIGHT; in rtnl_route_nh_set_weight()
282 uint8_t rtnl_route_nh_get_weight(struct rtnl_nexthop *nh) in rtnl_route_nh_get_weight() argument
284 return nh->rtnh_weight; in rtnl_route_nh_get_weight()
287 void rtnl_route_nh_set_ifindex(struct rtnl_nexthop *nh, int ifindex) in rtnl_route_nh_set_ifindex() argument
289 nh->rtnh_ifindex = ifindex; in rtnl_route_nh_set_ifindex()
290 nh->ce_mask |= NH_ATTR_IFINDEX; in rtnl_route_nh_set_ifindex()
293 int rtnl_route_nh_get_ifindex(struct rtnl_nexthop *nh) in rtnl_route_nh_get_ifindex() argument
295 return nh->rtnh_ifindex; in rtnl_route_nh_get_ifindex()
299 void rtnl_route_nh_set_gateway(struct rtnl_nexthop *nh, struct nl_addr *addr) in rtnl_route_nh_set_gateway() argument
301 struct nl_addr *old = nh->rtnh_gateway; in rtnl_route_nh_set_gateway()
304 nh->rtnh_gateway = nl_addr_get(addr); in rtnl_route_nh_set_gateway()
305 nh->ce_mask |= NH_ATTR_GATEWAY; in rtnl_route_nh_set_gateway()
307 nh->ce_mask &= ~NH_ATTR_GATEWAY; in rtnl_route_nh_set_gateway()
308 nh->rtnh_gateway = NULL; in rtnl_route_nh_set_gateway()
315 struct nl_addr *rtnl_route_nh_get_gateway(struct rtnl_nexthop *nh) in rtnl_route_nh_get_gateway() argument
317 return nh->rtnh_gateway; in rtnl_route_nh_get_gateway()
320 void rtnl_route_nh_set_flags(struct rtnl_nexthop *nh, unsigned int flags) in rtnl_route_nh_set_flags() argument
322 nh->rtnh_flag_mask |= flags; in rtnl_route_nh_set_flags()
323 nh->rtnh_flags |= flags; in rtnl_route_nh_set_flags()
324 nh->ce_mask |= NH_ATTR_FLAGS; in rtnl_route_nh_set_flags()
327 void rtnl_route_nh_unset_flags(struct rtnl_nexthop *nh, unsigned int flags) in rtnl_route_nh_unset_flags() argument
329 nh->rtnh_flag_mask |= flags; in rtnl_route_nh_unset_flags()
330 nh->rtnh_flags &= ~flags; in rtnl_route_nh_unset_flags()
331 nh->ce_mask |= NH_ATTR_FLAGS; in rtnl_route_nh_unset_flags()
334 unsigned int rtnl_route_nh_get_flags(struct rtnl_nexthop *nh) in rtnl_route_nh_get_flags() argument
336 return nh->rtnh_flags; in rtnl_route_nh_get_flags()
339 void rtnl_route_nh_set_realms(struct rtnl_nexthop *nh, uint32_t realms) in rtnl_route_nh_set_realms() argument
341 nh->rtnh_realms = realms; in rtnl_route_nh_set_realms()
342 nh->ce_mask |= NH_ATTR_REALMS; in rtnl_route_nh_set_realms()
345 uint32_t rtnl_route_nh_get_realms(struct rtnl_nexthop *nh) in rtnl_route_nh_get_realms() argument
347 return nh->rtnh_realms; in rtnl_route_nh_get_realms()
350 int rtnl_route_nh_set_newdst(struct rtnl_nexthop *nh, struct nl_addr *addr) in rtnl_route_nh_set_newdst() argument
352 struct nl_addr *old = nh->rtnh_newdst; in rtnl_route_nh_set_newdst()
359 nh->rtnh_newdst = nl_addr_get(addr); in rtnl_route_nh_set_newdst()
360 nh->ce_mask |= NH_ATTR_NEWDST; in rtnl_route_nh_set_newdst()
362 nh->ce_mask &= ~NH_ATTR_NEWDST; in rtnl_route_nh_set_newdst()
363 nh->rtnh_newdst = NULL; in rtnl_route_nh_set_newdst()
372 struct nl_addr *rtnl_route_nh_get_newdst(struct rtnl_nexthop *nh) in rtnl_route_nh_get_newdst() argument
374 return nh->rtnh_newdst; in rtnl_route_nh_get_newdst()
377 int rtnl_route_nh_set_via(struct rtnl_nexthop *nh, struct nl_addr *addr) in rtnl_route_nh_set_via() argument
379 struct nl_addr *old = nh->rtnh_via; in rtnl_route_nh_set_via()
386 nh->rtnh_via = nl_addr_get(addr); in rtnl_route_nh_set_via()
387 nh->ce_mask |= NH_ATTR_VIA; in rtnl_route_nh_set_via()
389 nh->ce_mask &= ~NH_ATTR_VIA; in rtnl_route_nh_set_via()
390 nh->rtnh_via= NULL; in rtnl_route_nh_set_via()
399 struct nl_addr *rtnl_route_nh_get_via(struct rtnl_nexthop *nh) in rtnl_route_nh_get_via() argument
401 return nh->rtnh_via; in rtnl_route_nh_get_via()