Lines Matching refs:route

2  * lib/route/route_obj.c	Route Object
13 * @ingroup route
38 #include <netlink/route/rtnl.h>
39 #include <netlink/route/route.h>
40 #include <netlink/route/link.h>
41 #include <netlink/route/nexthop.h>
132 link_cache = nl_cache_mngt_require("route/link");
212 link_cache = nl_cache_mngt_require("route/link");
277 struct rtnl_route *route = (struct rtnl_route *) obj;
281 if (route->ce_mask & ROUTE_ATTR_CACHEINFO) {
282 struct rtnl_rtcacheinfo *ci = &route->rt_cacheinfo;
294 struct rtnl_route *route = (struct rtnl_route *) obj;
298 link_cache = nl_cache_mngt_require("route/link");
301 nl_af2str(route->rt_family, buf, sizeof(buf)));
303 if (route->ce_mask & ROUTE_ATTR_DST)
305 nl_addr2str(route->rt_dst, buf, sizeof(buf)));
307 if (route->ce_mask & ROUTE_ATTR_SRC)
309 nl_addr2str(route->rt_src, buf, sizeof(buf)));
311 if (route->ce_mask & ROUTE_ATTR_PREF_SRC)
313 nl_addr2str(route->rt_pref_src, buf, sizeof(buf)));
315 if (route->ce_mask & ROUTE_ATTR_IIF) {
318 rtnl_link_i2name(link_cache, route->rt_iif,
321 nl_dump_line(p, "ROUTE_IIF=%d", route->rt_iif);
324 if (route->ce_mask & ROUTE_ATTR_TOS)
325 nl_dump_line(p, "ROUTE_TOS=%u\n", route->rt_tos);
327 if (route->ce_mask & ROUTE_ATTR_TABLE)
329 route->rt_table);
331 if (route->ce_mask & ROUTE_ATTR_SCOPE)
333 rtnl_scope2str(route->rt_scope, buf, sizeof(buf)));
335 if (route->ce_mask & ROUTE_ATTR_PRIO)
337 route->rt_prio);
339 if (route->ce_mask & ROUTE_ATTR_TYPE)
341 nl_rtntype2str(route->rt_type, buf, sizeof(buf)));
343 if (route->ce_mask & ROUTE_ATTR_MULTIPATH) {
347 if (route->rt_nr_nh > 0)
348 nl_dump_line(p, "ROUTE_NR_NH=%u\n", route->rt_nr_nh);
350 nl_list_for_each_entry(nh, &route->rt_nexthops, rtnh_list) {
495 void rtnl_route_get(struct rtnl_route *route)
497 nl_object_get((struct nl_object *) route);
500 void rtnl_route_put(struct rtnl_route *route)
502 nl_object_put((struct nl_object *) route);
512 void rtnl_route_set_table(struct rtnl_route *route, uint32_t table)
514 route->rt_table = table;
515 route->ce_mask |= ROUTE_ATTR_TABLE;
518 uint32_t rtnl_route_get_table(struct rtnl_route *route)
520 return route->rt_table;
523 void rtnl_route_set_scope(struct rtnl_route *route, uint8_t scope)
525 route->rt_scope = scope;
526 route->ce_mask |= ROUTE_ATTR_SCOPE;
529 uint8_t rtnl_route_get_scope(struct rtnl_route *route)
531 return route->rt_scope;
534 void rtnl_route_set_tos(struct rtnl_route *route, uint8_t tos)
536 route->rt_tos = tos;
537 route->ce_mask |= ROUTE_ATTR_TOS;
540 uint8_t rtnl_route_get_tos(struct rtnl_route *route)
542 return route->rt_tos;
545 void rtnl_route_set_protocol(struct rtnl_route *route, uint8_t protocol)
547 route->rt_protocol = protocol;
548 route->ce_mask |= ROUTE_ATTR_PROTOCOL;
551 uint8_t rtnl_route_get_protocol(struct rtnl_route *route)
553 return route->rt_protocol;
556 void rtnl_route_set_priority(struct rtnl_route *route, uint32_t prio)
558 route->rt_prio = prio;
559 route->ce_mask |= ROUTE_ATTR_PRIO;
562 uint32_t rtnl_route_get_priority(struct rtnl_route *route)
564 return route->rt_prio;
567 int rtnl_route_set_family(struct rtnl_route *route, uint8_t family)
572 route->rt_family = family;
573 route->ce_mask |= ROUTE_ATTR_FAMILY;
578 uint8_t rtnl_route_get_family(struct rtnl_route *route)
580 return route->rt_family;
583 int rtnl_route_set_dst(struct rtnl_route *route, struct nl_addr *addr)
585 if (route->ce_mask & ROUTE_ATTR_FAMILY) {
586 if (addr->a_family != route->rt_family)
589 route->rt_family = addr->a_family;
591 if (route->rt_dst)
592 nl_addr_put(route->rt_dst);
595 route->rt_dst = addr;
597 route->ce_mask |= (ROUTE_ATTR_DST | ROUTE_ATTR_FAMILY);
602 struct nl_addr *rtnl_route_get_dst(struct rtnl_route *route)
604 return route->rt_dst;
607 int rtnl_route_set_src(struct rtnl_route *route, struct nl_addr *addr)
612 if (route->ce_mask & ROUTE_ATTR_FAMILY) {
613 if (addr->a_family != route->rt_family)
616 route->rt_family = addr->a_family;
618 if (route->rt_src)
619 nl_addr_put(route->rt_src);
622 route->rt_src = addr;
623 route->ce_mask |= (ROUTE_ATTR_SRC | ROUTE_ATTR_FAMILY);
628 struct nl_addr *rtnl_route_get_src(struct rtnl_route *route)
630 return route->rt_src;
633 int rtnl_route_set_type(struct rtnl_route *route, uint8_t type)
638 route->rt_type = type;
639 route->ce_mask |= ROUTE_ATTR_TYPE;
644 uint8_t rtnl_route_get_type(struct rtnl_route *route)
646 return route->rt_type;
649 void rtnl_route_set_flags(struct rtnl_route *route, uint32_t flags)
651 route->rt_flag_mask |= flags;
652 route->rt_flags |= flags;
653 route->ce_mask |= ROUTE_ATTR_FLAGS;
656 void rtnl_route_unset_flags(struct rtnl_route *route, uint32_t flags)
658 route->rt_flag_mask |= flags;
659 route->rt_flags &= ~flags;
660 route->ce_mask |= ROUTE_ATTR_FLAGS;
663 uint32_t rtnl_route_get_flags(struct rtnl_route *route)
665 return route->rt_flags;
668 int rtnl_route_set_metric(struct rtnl_route *route, int metric, uint32_t value)
673 route->rt_metrics[metric - 1] = value;
675 if (!(route->rt_metrics_mask & (1 << (metric - 1)))) {
676 route->rt_nmetrics++;
677 route->rt_metrics_mask |= (1 << (metric - 1));
680 route->ce_mask |= ROUTE_ATTR_METRICS;
685 int rtnl_route_unset_metric(struct rtnl_route *route, int metric)
690 if (route->rt_metrics_mask & (1 << (metric - 1))) {
691 route->rt_nmetrics--;
692 route->rt_metrics_mask &= ~(1 << (metric - 1));
698 int rtnl_route_get_metric(struct rtnl_route *route, int metric, uint32_t *value)
703 if (!(route->rt_metrics_mask & (1 << (metric - 1))))
707 *value = route->rt_metrics[metric - 1];
712 int rtnl_route_set_pref_src(struct rtnl_route *route, struct nl_addr *addr)
714 if (route->ce_mask & ROUTE_ATTR_FAMILY) {
715 if (addr->a_family != route->rt_family)
718 route->rt_family = addr->a_family;
720 if (route->rt_pref_src)
721 nl_addr_put(route->rt_pref_src);
724 route->rt_pref_src = addr;
725 route->ce_mask |= (ROUTE_ATTR_PREF_SRC | ROUTE_ATTR_FAMILY);
730 struct nl_addr *rtnl_route_get_pref_src(struct rtnl_route *route)
732 return route->rt_pref_src;
735 void rtnl_route_set_iif(struct rtnl_route *route, int ifindex)
737 route->rt_iif = ifindex;
738 route->ce_mask |= ROUTE_ATTR_IIF;
741 int rtnl_route_get_iif(struct rtnl_route *route)
743 return route->rt_iif;
746 void rtnl_route_add_nexthop(struct rtnl_route *route, struct rtnl_nexthop *nh)
748 nl_list_add_tail(&nh->rtnh_list, &route->rt_nexthops);
749 route->rt_nr_nh++;
750 route->ce_mask |= ROUTE_ATTR_MULTIPATH;
753 void rtnl_route_remove_nexthop(struct rtnl_route *route, struct rtnl_nexthop *nh)
755 route->rt_nr_nh--;
759 struct nl_list_head *rtnl_route_get_nexthops(struct rtnl_route *route)
761 return &route->rt_nexthops;
764 int rtnl_route_get_nnexthops(struct rtnl_route *route)
766 return route->rt_nr_nh;
805 * Guess scope of a route object.
806 * @arg route Route object.
808 * Guesses the scope of a route object, based on the following rules:
810 * 1) Local route -> local scope
817 int rtnl_route_guess_scope(struct rtnl_route *route)
819 if (route->rt_type == RTN_LOCAL)
822 if (!nl_list_empty(&route->rt_nexthops)) {
829 nl_list_for_each_entry(nh, &route->rt_nexthops, rtnh_list) {
850 static int parse_multipath(struct rtnl_route *route, struct nlattr *attr)
880 route->rt_family);
898 rtnl_route_add_nexthop(route, nh);
914 struct rtnl_route *route;
920 route = rtnl_route_alloc();
921 if (!route) {
926 route->ce_msgtype = nlh->nlmsg_type;
933 route->rt_family = family = rtm->rtm_family;
934 route->rt_tos = rtm->rtm_tos;
935 route->rt_table = rtm->rtm_table;
936 route->rt_type = rtm->rtm_type;
937 route->rt_scope = rtm->rtm_scope;
938 route->rt_protocol = rtm->rtm_protocol;
939 route->rt_flags = rtm->rtm_flags;
941 route->ce_mask |= ROUTE_ATTR_FAMILY | ROUTE_ATTR_TOS |
956 err = rtnl_route_set_dst(route, dst);
971 rtnl_route_set_src(route, src);
976 rtnl_route_set_iif(route, nla_get_u32(tb[RTA_IIF]));
979 rtnl_route_set_priority(route, nla_get_u32(tb[RTA_PRIORITY]));
984 rtnl_route_set_pref_src(route, addr);
999 if (rtnl_route_set_metric(route, i, m) < 0)
1006 if ((err = parse_multipath(route, tb[RTA_MULTIPATH])) < 0)
1010 nla_memcpy(&route->rt_cacheinfo, tb[RTA_CACHEINFO],
1011 sizeof(route->rt_cacheinfo));
1012 route->ce_mask |= ROUTE_ATTR_CACHEINFO;
1041 if (route->rt_nr_nh == 0) {
1045 rtnl_route_add_nexthop(route, old_nh);
1051 first = nl_list_first_entry(&route->rt_nexthops,
1067 *result = route;
1071 rtnl_route_put(route);
1079 int rtnl_route_build_msg(struct nl_msg *msg, struct rtnl_route *route)
1084 .rtm_family = route->rt_family,
1085 .rtm_tos = route->rt_tos,
1086 .rtm_table = route->rt_table,
1087 .rtm_protocol = route->rt_protocol,
1088 .rtm_scope = route->rt_scope,
1089 .rtm_type = route->rt_type,
1090 .rtm_flags = route->rt_flags,
1093 if (route->rt_dst == NULL)
1096 rtmsg.rtm_dst_len = nl_addr_get_prefixlen(route->rt_dst);
1097 if (route->rt_src)
1098 rtmsg.rtm_src_len = nl_addr_get_prefixlen(route->rt_src);
1102 rtmsg.rtm_scope = rtnl_route_guess_scope(route);
1109 NLA_PUT_U32(msg, RTA_TABLE, route->rt_table);
1111 if (nl_addr_get_len(route->rt_dst))
1112 NLA_PUT_ADDR(msg, RTA_DST, route->rt_dst);
1113 NLA_PUT_U32(msg, RTA_PRIORITY, route->rt_prio);
1115 if (route->ce_mask & ROUTE_ATTR_SRC)
1116 NLA_PUT_ADDR(msg, RTA_SRC, route->rt_src);
1118 if (route->ce_mask & ROUTE_ATTR_PREF_SRC)
1119 NLA_PUT_ADDR(msg, RTA_PREFSRC, route->rt_pref_src);
1121 if (route->ce_mask & ROUTE_ATTR_IIF)
1122 NLA_PUT_U32(msg, RTA_IIF, route->rt_iif);
1124 if (route->rt_nmetrics > 0) {
1132 if (!rtnl_route_get_metric(route, i, &val))
1139 if (rtnl_route_get_nnexthops(route) > 0) {
1146 nl_list_for_each_entry(nh, &route->rt_nexthops, rtnh_list) {
1179 .oo_name = "route/route",