Lines Matching defs:nh
39 struct rtnl_nexthop *nh;
41 nh = calloc(1, sizeof(*nh));
42 if (!nh)
45 nl_init_list_head(&nh->rtnh_list);
47 return nh;
52 struct rtnl_nexthop *nh;
54 nh = rtnl_route_nh_alloc();
55 if (!nh)
58 nh->rtnh_flags = src->rtnh_flags;
59 nh->rtnh_flag_mask = src->rtnh_flag_mask;
60 nh->rtnh_weight = src->rtnh_weight;
61 nh->rtnh_ifindex = src->rtnh_ifindex;
62 nh->ce_mask = src->ce_mask;
65 nh->rtnh_gateway = nl_addr_clone(src->rtnh_gateway);
66 if (!nh->rtnh_gateway) {
67 free(nh);
72 return nh;
75 void rtnl_route_nh_free(struct rtnl_nexthop *nh)
77 nl_addr_put(nh->rtnh_gateway);
78 free(nh);
107 static void nh_dump_line(struct rtnl_nexthop *nh, struct nl_dump_params *dp)
116 if (nh->ce_mask & NH_ATTR_GATEWAY)
117 nl_dump(dp, " %s", nl_addr2str(nh->rtnh_gateway,
120 if(nh->ce_mask & NH_ATTR_IFINDEX) {
124 nh->rtnh_ifindex,
127 nl_dump(dp, " dev %d", nh->rtnh_ifindex);
133 static void nh_dump_details(struct rtnl_nexthop *nh, struct nl_dump_params *dp)
142 if (nh->ce_mask & NH_ATTR_GATEWAY)
143 nl_dump(dp, " via %s", nl_addr2str(nh->rtnh_gateway,
146 if(nh->ce_mask & NH_ATTR_IFINDEX) {
150 nh->rtnh_ifindex,
153 nl_dump(dp, " dev %d", nh->rtnh_ifindex);
156 if (nh->ce_mask & NH_ATTR_WEIGHT)
157 nl_dump(dp, " weight %u", nh->rtnh_weight);
159 if (nh->ce_mask & NH_ATTR_REALMS)
161 RTNL_REALM_FROM(nh->rtnh_realms),
162 RTNL_REALM_TO(nh->rtnh_realms));
164 if (nh->ce_mask & NH_ATTR_FLAGS)
165 nl_dump(dp, " <%s>", rtnl_route_nh_flags2str(nh->rtnh_flags,
169 static void nh_dump_env(struct rtnl_nexthop *nh, struct nl_dump_params *dp)
176 if (nh->ce_mask & NH_ATTR_GATEWAY)
178 nl_addr2str(nh->rtnh_gateway, buf, sizeof(buf)));
180 if(nh->ce_mask & NH_ATTR_IFINDEX) {
184 nh->rtnh_ifindex,
188 nh->rtnh_ifindex);
191 if (nh->ce_mask & NH_ATTR_WEIGHT)
193 nh->rtnh_weight);
195 if (nh->ce_mask & NH_ATTR_REALMS)
197 RTNL_REALM_FROM(nh->rtnh_realms),
198 RTNL_REALM_TO(nh->rtnh_realms));
200 if (nh->ce_mask & NH_ATTR_FLAGS)
202 rtnl_route_nh_flags2str(nh->rtnh_flags,
205 void rtnl_route_nh_dump(struct rtnl_nexthop *nh, struct nl_dump_params *dp)
209 nh_dump_line(nh, dp);
215 nh_dump_details(nh, dp);
219 nh_dump_env(nh, dp);
232 void rtnl_route_nh_set_weight(struct rtnl_nexthop *nh, uint8_t weight)
234 nh->rtnh_weight = weight;
235 nh->ce_mask |= NH_ATTR_WEIGHT;
238 uint8_t rtnl_route_nh_get_weight(struct rtnl_nexthop *nh)
240 return nh->rtnh_weight;
243 void rtnl_route_nh_set_ifindex(struct rtnl_nexthop *nh, int ifindex)
245 nh->rtnh_ifindex = ifindex;
246 nh->ce_mask |= NH_ATTR_IFINDEX;
249 int rtnl_route_nh_get_ifindex(struct rtnl_nexthop *nh)
251 return nh->rtnh_ifindex;
254 void rtnl_route_nh_set_gateway(struct rtnl_nexthop *nh, struct nl_addr *addr)
256 struct nl_addr *old = nh->rtnh_gateway;
259 nh->rtnh_gateway = nl_addr_get(addr);
260 nh->ce_mask |= NH_ATTR_GATEWAY;
262 nh->ce_mask &= ~NH_ATTR_GATEWAY;
263 nh->rtnh_gateway = NULL;
270 struct nl_addr *rtnl_route_nh_get_gateway(struct rtnl_nexthop *nh)
272 return nh->rtnh_gateway;
275 void rtnl_route_nh_set_flags(struct rtnl_nexthop *nh, unsigned int flags)
277 nh->rtnh_flag_mask |= flags;
278 nh->rtnh_flags |= flags;
279 nh->ce_mask |= NH_ATTR_FLAGS;
282 void rtnl_route_nh_unset_flags(struct rtnl_nexthop *nh, unsigned int flags)
284 nh->rtnh_flag_mask |= flags;
285 nh->rtnh_flags &= ~flags;
286 nh->ce_mask |= NH_ATTR_FLAGS;
289 unsigned int rtnl_route_nh_get_flags(struct rtnl_nexthop *nh)
291 return nh->rtnh_flags;
294 void rtnl_route_nh_set_realms(struct rtnl_nexthop *nh, uint32_t realms)
296 nh->rtnh_realms = realms;
297 nh->ce_mask |= NH_ATTR_REALMS;
300 uint32_t rtnl_route_nh_get_realms(struct rtnl_nexthop *nh)
302 return nh->rtnh_realms;