libnl 1.1.4
Modules | Variables

Modules

 Nexthop
 

Variables

struct nl_object_ops route_obj_ops
 

Allocation/Freeing

struct rtnl_route * rtnl_route_alloc (void)
 
void rtnl_route_get (struct rtnl_route *route)
 
void rtnl_route_put (struct rtnl_route *route)
 

Attributes

void rtnl_route_set_table (struct rtnl_route *route, int table)
 
int rtnl_route_get_table (struct rtnl_route *route)
 
void rtnl_route_set_scope (struct rtnl_route *route, int scope)
 
int rtnl_route_get_scope (struct rtnl_route *route)
 
void rtnl_route_set_tos (struct rtnl_route *route, int tos)
 
int rtnl_route_get_tos (struct rtnl_route *route)
 
void rtnl_route_set_realms (struct rtnl_route *route, realm_t realms)
 
realm_t rtnl_route_get_realms (struct rtnl_route *route)
 
void rtnl_route_set_protocol (struct rtnl_route *route, int proto)
 
int rtnl_route_get_protocol (struct rtnl_route *route)
 
void rtnl_route_set_prio (struct rtnl_route *route, int prio)
 
int rtnl_route_get_prio (struct rtnl_route *route)
 
void rtnl_route_set_family (struct rtnl_route *route, int family)
 
int rtnl_route_get_family (struct rtnl_route *route)
 
int rtnl_route_set_dst (struct rtnl_route *route, struct nl_addr *addr)
 
struct nl_addr * rtnl_route_get_dst (struct rtnl_route *route)
 
int rtnl_route_get_dst_len (struct rtnl_route *route)
 
int rtnl_route_set_src (struct rtnl_route *route, struct nl_addr *addr)
 
struct nl_addr * rtnl_route_get_src (struct rtnl_route *route)
 
int rtnl_route_get_src_len (struct rtnl_route *route)
 
int rtnl_route_set_gateway (struct rtnl_route *route, struct nl_addr *addr)
 
struct nl_addr * rtnl_route_get_gateway (struct rtnl_route *route)
 
void rtnl_route_set_type (struct rtnl_route *route, int type)
 
int rtnl_route_get_type (struct rtnl_route *route)
 
void rtnl_route_set_flags (struct rtnl_route *route, unsigned int flags)
 
void rtnl_route_unset_flags (struct rtnl_route *route, unsigned int flags)
 
unsigned int rtnl_route_get_flags (struct rtnl_route *route)
 
int rtnl_route_set_metric (struct rtnl_route *route, int metric, uint32_t value)
 
int rtnl_route_unset_metric (struct rtnl_route *route, int metric)
 
unsigned int rtnl_route_get_metric (struct rtnl_route *route, int metric)
 
int rtnl_route_set_pref_src (struct rtnl_route *route, struct nl_addr *addr)
 
struct nl_addr * rtnl_route_get_pref_src (struct rtnl_route *route)
 
void rtnl_route_set_oif (struct rtnl_route *route, int ifindex)
 
int rtnl_route_get_oif (struct rtnl_route *route)
 
void rtnl_route_set_iif (struct rtnl_route *route, const char *name)
 
char * rtnl_route_get_iif (struct rtnl_route *route)
 
void rtnl_route_add_nexthop (struct rtnl_route *route, struct rtnl_nexthop *nh)
 
void rtnl_route_remove_nexthop (struct rtnl_nexthop *nh)
 
struct nl_list_headrtnl_route_get_nexthops (struct rtnl_route *route)
 
void rtnl_route_set_cacheinfo (struct rtnl_route *route, struct rtnl_rtcacheinfo *ci)
 
uint32_t rtnl_route_get_mp_algo (struct rtnl_route *route)
 
void rtnl_route_set_mp_algo (struct rtnl_route *route, uint32_t algo)
 

Detailed Description

Attributes
Name Default
-------------------------------------------------------------
routing table RT_TABLE_MAIN
scope RT_SCOPE_NOWHERE
tos 0
realms 0
protocol RTPROT_STATIC
prio 0
family AF_UNSPEC
type RTN_UNICAST
iif NULL
mpalgo IP_MP_ALG_NONE

Function Documentation

◆ rtnl_route_alloc()

struct rtnl_route * rtnl_route_alloc ( void  )

Definition at line 538 of file route_obj.c.

539{
540 return (struct rtnl_route *) nl_object_alloc(&route_obj_ops);
541}
struct nl_object * nl_object_alloc(struct nl_object_ops *ops)
Allocate a new object of kind specified by the operations handle.
Definition: object.c:42

◆ rtnl_route_get()

void rtnl_route_get ( struct rtnl_route *  route)

Definition at line 543 of file route_obj.c.

544{
545 nl_object_get((struct nl_object *) route);
546}
void nl_object_get(struct nl_object *obj)
Acquire a reference on a object.
Definition: object.c:167

◆ rtnl_route_put()

void rtnl_route_put ( struct rtnl_route *  route)

Definition at line 548 of file route_obj.c.

549{
550 nl_object_put((struct nl_object *) route);
551}
void nl_object_put(struct nl_object *obj)
Release a reference from an object.
Definition: object.c:178

◆ rtnl_route_set_table()

void rtnl_route_set_table ( struct rtnl_route *  route,
int  table 
)

Definition at line 560 of file route_obj.c.

561{
562 route->rt_table = table;
563 route->ce_mask |= ROUTE_ATTR_TABLE;
564}

◆ rtnl_route_get_table()

int rtnl_route_get_table ( struct rtnl_route *  route)

Definition at line 566 of file route_obj.c.

567{
568 if (route->ce_mask & ROUTE_ATTR_TABLE)
569 return route->rt_table;
570 else
571 return RT_TABLE_MAIN;
572}

◆ rtnl_route_set_scope()

void rtnl_route_set_scope ( struct rtnl_route *  route,
int  scope 
)

Definition at line 574 of file route_obj.c.

575{
576 route->rt_scope = scope;
577 route->ce_mask |= ROUTE_ATTR_SCOPE;
578}

◆ rtnl_route_get_scope()

int rtnl_route_get_scope ( struct rtnl_route *  route)

Definition at line 580 of file route_obj.c.

581{
582 if (route->ce_mask & ROUTE_ATTR_SCOPE)
583 return route->rt_scope;
584 else
585 return RT_SCOPE_NOWHERE;
586}

◆ rtnl_route_set_tos()

void rtnl_route_set_tos ( struct rtnl_route *  route,
int  tos 
)

Definition at line 588 of file route_obj.c.

589{
590 route->rt_tos = tos;
591 route->ce_mask |= ROUTE_ATTR_TOS;
592}

◆ rtnl_route_get_tos()

int rtnl_route_get_tos ( struct rtnl_route *  route)

Definition at line 594 of file route_obj.c.

595{
596 return route->rt_tos;
597}

◆ rtnl_route_set_realms()

void rtnl_route_set_realms ( struct rtnl_route *  route,
realm_t  realms 
)

Definition at line 599 of file route_obj.c.

600{
601 route->rt_realms = realms;
602 route->ce_mask |= ROUTE_ATTR_REALMS;
603}

◆ rtnl_route_get_realms()

realm_t rtnl_route_get_realms ( struct rtnl_route *  route)

Definition at line 605 of file route_obj.c.

606{
607 return route->rt_realms;
608}

◆ rtnl_route_set_protocol()

void rtnl_route_set_protocol ( struct rtnl_route *  route,
int  proto 
)

Definition at line 610 of file route_obj.c.

611{
612 route->rt_protocol = proto;
613 route->ce_mask |= ROUTE_ATTR_PROTOCOL;
614}

◆ rtnl_route_get_protocol()

int rtnl_route_get_protocol ( struct rtnl_route *  route)

Definition at line 616 of file route_obj.c.

617{
618 if (route->ce_mask & ROUTE_ATTR_PROTOCOL)
619 return route->rt_protocol;
620 else
621 return RTPROT_STATIC;
622}

◆ rtnl_route_set_prio()

void rtnl_route_set_prio ( struct rtnl_route *  route,
int  prio 
)

Definition at line 624 of file route_obj.c.

625{
626 route->rt_prio = prio;
627 route->ce_mask |= ROUTE_ATTR_PRIO;
628}

◆ rtnl_route_get_prio()

int rtnl_route_get_prio ( struct rtnl_route *  route)

Definition at line 630 of file route_obj.c.

631{
632 return route->rt_prio;
633}

◆ rtnl_route_set_family()

void rtnl_route_set_family ( struct rtnl_route *  route,
int  family 
)

Definition at line 635 of file route_obj.c.

636{
637 route->rt_family = family;
638 route->ce_mask |= ROUTE_ATTR_FAMILY;
639}

◆ rtnl_route_get_family()

int rtnl_route_get_family ( struct rtnl_route *  route)

Definition at line 641 of file route_obj.c.

642{
643 if (route->ce_mask & ROUTE_ATTR_FAMILY)
644 return route->rt_family;
645 else
646 return AF_UNSPEC;
647}

◆ rtnl_route_set_dst()

int rtnl_route_set_dst ( struct rtnl_route *  route,
struct nl_addr *  addr 
)

Definition at line 649 of file route_obj.c.

650{
651 if (route->ce_mask & ROUTE_ATTR_FAMILY) {
652 if (addr->a_family != route->rt_family)
653 return nl_error(EINVAL, "Address family mismatch");
654 } else
655 route->rt_family = addr->a_family;
656
657 if (route->rt_dst)
658 nl_addr_put(route->rt_dst);
659
660 nl_addr_get(addr);
661 route->rt_dst = addr;
662
663 route->ce_mask |= (ROUTE_ATTR_DST | ROUTE_ATTR_FAMILY);
664
665 return 0;
666}

◆ rtnl_route_get_dst()

struct nl_addr * rtnl_route_get_dst ( struct rtnl_route *  route)

Definition at line 668 of file route_obj.c.

669{
670 return route->rt_dst;
671}

◆ rtnl_route_get_dst_len()

int rtnl_route_get_dst_len ( struct rtnl_route *  route)

Definition at line 673 of file route_obj.c.

674{
675 if (route->ce_mask & ROUTE_ATTR_DST)
676 return nl_addr_get_prefixlen(route->rt_dst);
677 else
678 return 0;
679}
unsigned int nl_addr_get_prefixlen(struct nl_addr *addr)
Get prefix length of abstract address object.
Definition: addr.c:779

◆ rtnl_route_set_src()

int rtnl_route_set_src ( struct rtnl_route *  route,
struct nl_addr *  addr 
)

Definition at line 681 of file route_obj.c.

682{
683 if (route->ce_mask & ROUTE_ATTR_FAMILY) {
684 if (addr->a_family != route->rt_family)
685 return nl_error(EINVAL, "Address family mismatch");
686 } else
687 route->rt_family = addr->a_family;
688
689 if (route->rt_src)
690 nl_addr_put(route->rt_src);
691
692 nl_addr_get(addr);
693 route->rt_src = addr;
694 route->ce_mask |= (ROUTE_ATTR_SRC | ROUTE_ATTR_FAMILY);
695
696 return 0;
697}

◆ rtnl_route_get_src()

struct nl_addr * rtnl_route_get_src ( struct rtnl_route *  route)

Definition at line 699 of file route_obj.c.

700{
701 return route->rt_src;
702}

◆ rtnl_route_get_src_len()

int rtnl_route_get_src_len ( struct rtnl_route *  route)

Definition at line 704 of file route_obj.c.

705{
706 if (route->ce_mask & ROUTE_ATTR_SRC)
707 return nl_addr_get_prefixlen(route->rt_src);
708 else
709 return 0;
710}

◆ rtnl_route_set_gateway()

int rtnl_route_set_gateway ( struct rtnl_route *  route,
struct nl_addr *  addr 
)

Definition at line 712 of file route_obj.c.

713{
714 if (route->ce_mask & ROUTE_ATTR_FAMILY) {
715 if (addr->a_family != route->rt_family)
716 return nl_error(EINVAL, "Address family mismatch");
717 } else
718 route->rt_family = addr->a_family;
719
720 if (route->rt_gateway)
721 nl_addr_put(route->rt_gateway);
722
723 nl_addr_get(addr);
724 route->rt_gateway = addr;
725 route->ce_mask |= (ROUTE_ATTR_GATEWAY | ROUTE_ATTR_FAMILY);
726
727 return 0;
728}

◆ rtnl_route_get_gateway()

struct nl_addr * rtnl_route_get_gateway ( struct rtnl_route *  route)

Definition at line 730 of file route_obj.c.

731{
732 return route->rt_gateway;
733}

◆ rtnl_route_set_type()

void rtnl_route_set_type ( struct rtnl_route *  route,
int  type 
)

Definition at line 735 of file route_obj.c.

736{
737 route->rt_type = type;
738 route->ce_mask |= ROUTE_ATTR_TYPE;
739}

◆ rtnl_route_get_type()

int rtnl_route_get_type ( struct rtnl_route *  route)

Definition at line 741 of file route_obj.c.

742{
743 if (route->ce_mask & ROUTE_ATTR_TYPE)
744 return route->rt_type;
745 else
746 return RTN_UNICAST;
747}

◆ rtnl_route_set_flags()

void rtnl_route_set_flags ( struct rtnl_route *  route,
unsigned int  flags 
)

Definition at line 749 of file route_obj.c.

750{
751 route->rt_flag_mask |= flags;
752 route->rt_flags |= flags;
753 route->ce_mask |= ROUTE_ATTR_FLAGS;
754}

◆ rtnl_route_unset_flags()

void rtnl_route_unset_flags ( struct rtnl_route *  route,
unsigned int  flags 
)

Definition at line 756 of file route_obj.c.

757{
758 route->rt_flag_mask |= flags;
759 route->rt_flags &= ~flags;
760 route->ce_mask |= ROUTE_ATTR_FLAGS;
761}

◆ rtnl_route_get_flags()

unsigned int rtnl_route_get_flags ( struct rtnl_route *  route)

Definition at line 763 of file route_obj.c.

764{
765 return route->rt_flags;
766}

◆ rtnl_route_set_metric()

int rtnl_route_set_metric ( struct rtnl_route *  route,
int  metric,
uint32_t  value 
)

Definition at line 768 of file route_obj.c.

769{
770 if (metric > RTAX_MAX || metric < 1)
771 return nl_error(EINVAL, "Metric out of range (1..%d)",
772 RTAX_MAX);
773
774 route->rt_metrics[metric - 1] = value;
775 route->rt_metrics_mask |= (1 << (metric - 1));
776
777 return 0;
778}

◆ rtnl_route_unset_metric()

int rtnl_route_unset_metric ( struct rtnl_route *  route,
int  metric 
)

Definition at line 780 of file route_obj.c.

781{
782 if (metric > RTAX_MAX || metric < 1)
783 return nl_error(EINVAL, "Metric out of range (1..%d)",
784 RTAX_MAX);
785
786 route->rt_metrics_mask &= ~(1 << (metric - 1));
787
788 return 0;
789}

◆ rtnl_route_get_metric()

unsigned int rtnl_route_get_metric ( struct rtnl_route *  route,
int  metric 
)

Definition at line 791 of file route_obj.c.

792{
793 if (metric > RTAX_MAX || metric < 1)
794 return UINT_MAX;
795
796 if (!(route->rt_metrics_mask & (1 << (metric - 1))))
797 return UINT_MAX;
798
799 return route->rt_metrics[metric - 1];
800}

◆ rtnl_route_set_pref_src()

int rtnl_route_set_pref_src ( struct rtnl_route *  route,
struct nl_addr *  addr 
)

Definition at line 802 of file route_obj.c.

803{
804 if (route->ce_mask & ROUTE_ATTR_FAMILY) {
805 if (addr->a_family != route->rt_family)
806 return nl_error(EINVAL, "Address family mismatch");
807 } else
808 route->rt_family = addr->a_family;
809
810 if (route->rt_pref_src)
811 nl_addr_put(route->rt_pref_src);
812
813 nl_addr_get(addr);
814 route->rt_pref_src = addr;
815 route->ce_mask |= (ROUTE_ATTR_PREF_SRC | ROUTE_ATTR_FAMILY);
816
817 return 0;
818}

◆ rtnl_route_get_pref_src()

struct nl_addr * rtnl_route_get_pref_src ( struct rtnl_route *  route)

Definition at line 820 of file route_obj.c.

821{
822 return route->rt_pref_src;
823}

◆ rtnl_route_set_oif()

void rtnl_route_set_oif ( struct rtnl_route *  route,
int  ifindex 
)

Definition at line 825 of file route_obj.c.

826{
827 route->rt_oif = ifindex;
828 route->ce_mask |= ROUTE_ATTR_OIF;
829}

◆ rtnl_route_get_oif()

int rtnl_route_get_oif ( struct rtnl_route *  route)

Definition at line 831 of file route_obj.c.

832{
833 if (route->ce_mask & ROUTE_ATTR_OIF)
834 return route->rt_oif;
835 else
836 return RTNL_LINK_NOT_FOUND;
837}

◆ rtnl_route_set_iif()

void rtnl_route_set_iif ( struct rtnl_route *  route,
const char *  name 
)

Definition at line 839 of file route_obj.c.

840{
841 strncpy(route->rt_iif, name, sizeof(route->rt_iif) - 1);
842 route->ce_mask |= ROUTE_ATTR_IIF;
843}

◆ rtnl_route_get_iif()

char * rtnl_route_get_iif ( struct rtnl_route *  route)

Definition at line 845 of file route_obj.c.

846{
847 if (route->ce_mask & ROUTE_ATTR_IIF)
848 return route->rt_iif;
849 else
850 return NULL;
851}

◆ rtnl_route_add_nexthop()

void rtnl_route_add_nexthop ( struct rtnl_route *  route,
struct rtnl_nexthop *  nh 
)

Definition at line 853 of file route_obj.c.

854{
855 nl_list_add_tail(&nh->rtnh_list, &route->rt_nexthops);
856 route->ce_mask |= ROUTE_ATTR_MULTIPATH;
857}

◆ rtnl_route_remove_nexthop()

void rtnl_route_remove_nexthop ( struct rtnl_nexthop *  nh)

Definition at line 859 of file route_obj.c.

860{
861 nl_list_del(&nh->rtnh_list);
862}

◆ rtnl_route_get_nexthops()

struct nl_list_head * rtnl_route_get_nexthops ( struct rtnl_route *  route)

Definition at line 864 of file route_obj.c.

865{
866 return &route->rt_nexthops;
867}

◆ rtnl_route_set_cacheinfo()

void rtnl_route_set_cacheinfo ( struct rtnl_route *  route,
struct rtnl_rtcacheinfo ci 
)

Definition at line 869 of file route_obj.c.

871{
872 memcpy(&route->rt_cacheinfo, ci, sizeof(*ci));
873 route->ce_mask |= ROUTE_ATTR_CACHEINFO;
874}

◆ rtnl_route_get_mp_algo()

uint32_t rtnl_route_get_mp_algo ( struct rtnl_route *  route)

Definition at line 876 of file route_obj.c.

877{
878 if (route->ce_mask & ROUTE_ATTR_MP_ALGO)
879 return route->rt_mp_algo;
880 else
881 return IP_MP_ALG_NONE;
882}

◆ rtnl_route_set_mp_algo()

void rtnl_route_set_mp_algo ( struct rtnl_route *  route,
uint32_t  algo 
)

Definition at line 884 of file route_obj.c.

885{
886 route->rt_mp_algo = algo;
887 route->ce_mask |= ROUTE_ATTR_MP_ALGO;
888}

Variable Documentation

◆ route_obj_ops

struct nl_object_ops route_obj_ops
Initial value:
= {
.oo_name = "route/route",
.oo_size = sizeof(struct rtnl_route),
.oo_constructor = route_constructor,
.oo_free_data = route_free_data,
.oo_clone = route_clone,
.oo_dump[NL_DUMP_BRIEF] = route_dump_brief,
.oo_dump[NL_DUMP_FULL] = route_dump_full,
.oo_dump[NL_DUMP_STATS] = route_dump_stats,
.oo_dump[NL_DUMP_XML] = route_dump_xml,
.oo_dump[NL_DUMP_ENV] = route_dump_env,
.oo_compare = route_compare,
.oo_attrs2str = route_attrs2str,
.oo_id_attrs = (ROUTE_ATTR_FAMILY | ROUTE_ATTR_TOS |
ROUTE_ATTR_TABLE | ROUTE_ATTR_DST),
}
@ NL_DUMP_FULL
Dump all attributes but no statistics.
Definition: types.h:23
@ NL_DUMP_BRIEF
Dump object in a brief one-liner.
Definition: types.h:22
@ NL_DUMP_ENV
Dump all attribtues as env variables.
Definition: types.h:26
@ NL_DUMP_STATS
Dump all attributes including statistics.
Definition: types.h:24
@ NL_DUMP_XML
Dump all attribtes in XML format.
Definition: types.h:25

Definition at line 892 of file route_obj.c.