libnl 1.1.4

Allocation/Freeing

struct rtnl_nexthop * rtnl_route_nh_alloc (void)
 
struct rtnl_nexthop * rtnl_route_nh_clone (struct rtnl_nexthop *src)
 
void rtnl_route_nh_free (struct rtnl_nexthop *nh)
 

Attributes

void rtnl_route_nh_set_weight (struct rtnl_nexthop *nh, int weight)
 
int rtnl_route_nh_get_weight (struct rtnl_nexthop *nh)
 
void rtnl_route_nh_set_ifindex (struct rtnl_nexthop *nh, int ifindex)
 
int rtnl_route_nh_get_ifindex (struct rtnl_nexthop *nh)
 
void rtnl_route_nh_set_gateway (struct rtnl_nexthop *nh, struct nl_addr *addr)
 
struct nl_addr * rtnl_route_nh_get_gateway (struct rtnl_nexthop *nh)
 
void rtnl_route_nh_set_flags (struct rtnl_nexthop *nh, unsigned int flags)
 
void rtnl_route_nh_unset_flags (struct rtnl_nexthop *nh, unsigned int flags)
 
unsigned int rtnl_route_nh_get_flags (struct rtnl_nexthop *nh)
 

Detailed Description

Function Documentation

◆ rtnl_route_nh_alloc()

struct rtnl_nexthop * rtnl_route_nh_alloc ( void  )

Definition at line 29 of file nexthop.c.

30{
31 struct rtnl_nexthop *nh;
32
33 nh = calloc(1, sizeof(*nh));
34 if (!nh) {
35 nl_errno(ENOMEM);
36 return NULL;
37 }
38
39 nl_init_list_head(&nh->rtnh_list);
40
41 return nh;
42}

◆ rtnl_route_nh_clone()

struct rtnl_nexthop * rtnl_route_nh_clone ( struct rtnl_nexthop *  src)

Definition at line 44 of file nexthop.c.

45{
46 struct rtnl_nexthop *nh;
47
48 nh = rtnl_route_nh_alloc();
49 if (!nh)
50 return NULL;
51
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;
57
58 if (src->rtnh_gateway) {
59 nh->rtnh_gateway = nl_addr_clone(src->rtnh_gateway);
60 if (!nh->rtnh_gateway) {
61 free(nh);
62 return NULL;
63 }
64 }
65
66 return nh;
67}
struct nl_addr * nl_addr_clone(struct nl_addr *addr)
Clone existing abstract address object.
Definition: addr.c:406

◆ rtnl_route_nh_free()

void rtnl_route_nh_free ( struct rtnl_nexthop *  nh)

Definition at line 69 of file nexthop.c.

70{
71 nl_addr_put(nh->rtnh_gateway);
72 free(nh);
73}

◆ rtnl_route_nh_set_weight()

void rtnl_route_nh_set_weight ( struct rtnl_nexthop *  nh,
int  weight 
)

Definition at line 81 of file nexthop.c.

82{
83 nh->rtnh_weight = weight;
84 nh->rtnh_mask |= NEXTHOP_HAS_WEIGHT;
85}

◆ rtnl_route_nh_get_weight()

int rtnl_route_nh_get_weight ( struct rtnl_nexthop *  nh)

Definition at line 87 of file nexthop.c.

88{
89 if (nh->rtnh_mask & NEXTHOP_HAS_WEIGHT)
90 return nh->rtnh_weight;
91 else
92 return 0;
93}

◆ rtnl_route_nh_set_ifindex()

void rtnl_route_nh_set_ifindex ( struct rtnl_nexthop *  nh,
int  ifindex 
)

Definition at line 95 of file nexthop.c.

96{
97 nh->rtnh_ifindex = ifindex;
98 nh->rtnh_mask |= NEXTHOP_HAS_IFINDEX;
99}

◆ rtnl_route_nh_get_ifindex()

int rtnl_route_nh_get_ifindex ( struct rtnl_nexthop *  nh)

Definition at line 101 of file nexthop.c.

102{
103 if (nh->rtnh_mask & NEXTHOP_HAS_IFINDEX)
104 return nh->rtnh_ifindex;
105 else
106 return -1;
107}

◆ rtnl_route_nh_set_gateway()

void rtnl_route_nh_set_gateway ( struct rtnl_nexthop *  nh,
struct nl_addr *  addr 
)

Definition at line 109 of file nexthop.c.

110{
111 struct nl_addr *old = nh->rtnh_gateway;
112
113 nh->rtnh_gateway = nl_addr_get(addr);
114 if (old)
115 nl_addr_put(old);
116
117 nh->rtnh_mask |= NEXTHOP_HAS_GATEWAY;
118}

◆ rtnl_route_nh_get_gateway()

struct nl_addr * rtnl_route_nh_get_gateway ( struct rtnl_nexthop *  nh)

Definition at line 120 of file nexthop.c.

121{
122 if (nh->rtnh_mask & NEXTHOP_HAS_GATEWAY)
123 return nh->rtnh_gateway;
124 else
125 return NULL;
126}

◆ rtnl_route_nh_set_flags()

void rtnl_route_nh_set_flags ( struct rtnl_nexthop *  nh,
unsigned int  flags 
)

Definition at line 128 of file nexthop.c.

129{
130 nh->rtnh_flag_mask |= flags;
131 nh->rtnh_flags |= flags;
132 nh->rtnh_mask |= NEXTHOP_HAS_FLAGS;
133}

◆ rtnl_route_nh_unset_flags()

void rtnl_route_nh_unset_flags ( struct rtnl_nexthop *  nh,
unsigned int  flags 
)

Definition at line 135 of file nexthop.c.

136{
137 nh->rtnh_flag_mask |= flags;
138 nh->rtnh_flags &= ~flags;
139 nh->rtnh_mask |= NEXTHOP_HAS_FLAGS;
140}

◆ rtnl_route_nh_get_flags()

unsigned int rtnl_route_nh_get_flags ( struct rtnl_nexthop *  nh)

Definition at line 142 of file nexthop.c.

143{
144 if (nh->rtnh_mask & NEXTHOP_HAS_FLAGS)
145 return nh->rtnh_flags;
146 else
147 return 0;
148}