libnl: /data/src/libnl3/lib/route/nl-route.h Source File

libnl 3.10.0

nl-route.h
1/* SPDX-License-Identifier: LGPL-2.1-only */
2/*
3 * Copyright (c) 2003-2013 Thomas Graf <tgraf@suug.ch>
4 * Copyright (c) 2013 Sassano Systems LLC <joe@sassanosystems.com>
5 */
6
7#ifndef __LIB_ROUTE_NL_ROUTE_H__
8#define __LIB_ROUTE_NL_ROUTE_H__
9
10#include <netlink/route/tc.h>
11
12#include "nl-priv-dynamic-core/object-api.h"
13#include "nl-priv-dynamic-route/nl-priv-dynamic-route.h"
14#include "nl-aux-core/nl-core.h"
15
16/*****************************************************************************/
17
18 struct rtnl_link_map {
19 uint64_t lm_mem_start;
20 uint64_t lm_mem_end;
21 uint64_t lm_base_addr;
22 uint16_t lm_irq;
23 uint8_t lm_dma;
24 uint8_t lm_port;
25};
26
27#define IFQDISCSIZ 32
28
29 struct rtnl_link {
30 NLHDR_COMMON
31
32 char l_name[IFNAMSIZ];
33 uint32_t l_family;
34 uint32_t l_arptype;
35 uint32_t l_index;
36 uint32_t l_flags;
37 uint32_t l_change;
38 uint32_t l_mtu;
39 uint32_t l_link;
40 int32_t l_link_netnsid;
41 uint32_t l_txqlen;
42 uint32_t l_weight;
43 uint32_t l_master;
44 struct nl_addr *l_addr;
45 struct nl_addr *l_bcast;
46 char l_qdisc[IFQDISCSIZ];
47 struct rtnl_link_map l_map;
48 uint64_t l_stats[RTNL_LINK_STATS_MAX + 1];
49 uint32_t l_flag_mask;
50 uint32_t l_num_vf;
51 uint8_t l_operstate;
52 uint8_t l_linkmode;
53 /* 2 byte hole */
54 char *l_info_kind;
55 char *l_info_slave_kind;
56 struct rtnl_link_info_ops *l_info_ops;
57 void *l_af_data[AF_MAX];
58 void *l_info;
59 char *l_ifalias;
60 uint32_t l_promiscuity;
61 uint32_t l_num_tx_queues;
62 uint32_t l_num_rx_queues;
63 uint32_t l_gso_max_segs;
64 uint32_t l_gso_max_size;
65 uint32_t l_group;
66 uint8_t l_carrier;
67 /* 3 byte hole */
68 uint32_t l_carrier_changes;
69 struct rtnl_link_af_ops *l_af_ops;
70 struct nl_data *l_phys_port_id;
71 char l_phys_port_name[IFNAMSIZ];
72 struct nl_data *l_phys_switch_id;
73 int l_ns_fd;
74 pid_t l_ns_pid;
75 struct rtnl_link_vf *l_vf_list;
76};
77
78 struct rtnl_nh_encap {
79 struct nh_encap_ops *ops;
80 void *priv; /* private data for encap type */
81};
82
83 struct rtnl_ratespec {
84 uint64_t rs_rate64;
85 uint16_t rs_overhead;
86 int16_t rs_cell_align;
87 uint16_t rs_mpu;
88 uint8_t rs_cell_log;
89};
90
91#define TCKINDSIZ 32
92
93#define NL_TC_GENERIC(pre) \
94 NLHDR_COMMON \
95 uint32_t pre##_family; \
96 uint32_t pre##_ifindex; \
97 uint32_t pre##_handle; \
98 uint32_t pre##_parent; \
99 uint32_t pre##_info; \
100 uint32_t pre##_mtu; \
101 uint32_t pre##_mpu; \
102 uint32_t pre##_overhead; \
103 uint32_t pre##_linktype; \
104 char pre##_kind[TCKINDSIZ]; \
105 struct nl_data *pre##_opts; \
106 uint64_t pre##_stats[RTNL_TC_STATS_MAX + 1]; \
107 struct nl_data *pre##_xstats; \
108 struct nl_data *pre##_subdata; \
109 struct rtnl_link *pre##_link; \
110 struct rtnl_tc_ops *pre##_ops; \
111 enum rtnl_tc_type pre##_type; \
112 uint32_t pre##_chain
113
114 struct rtnl_tc {
115 NL_TC_GENERIC(tc);
116};
117
118 struct rtnl_qdisc {
119 NL_TC_GENERIC(q);
120};
121
122 struct rtnl_act {
123 NL_TC_GENERIC(c);
124 struct rtnl_act *a_next;
125};
126
127/*****************************************************************************/
128
129static inline void rtnl_copy_ratespec(struct rtnl_ratespec *dst,
130 struct tc_ratespec *src)
131{
132 dst->rs_cell_log = src->cell_log;
133 dst->rs_overhead = src->overhead;
134 dst->rs_cell_align = src->cell_align;
135 dst->rs_mpu = src->mpu;
136 dst->rs_rate64 = src->rate;
137}
138
139static inline void rtnl_rcopy_ratespec(struct tc_ratespec *dst,
140 struct rtnl_ratespec *src)
141{
142 dst->cell_log = src->rs_cell_log;
143 dst->overhead = src->rs_overhead;
144 dst->cell_align = src->rs_cell_align;
145 dst->mpu = src->rs_mpu;
146 dst->rate = src->rs_rate64 > 0xFFFFFFFFull ? 0xFFFFFFFFull :
147 (uint32_t)src->rs_rate64;
148}
149
150/*****************************************************************************/
151
152static inline int build_sysconf_path(char **strp, const char *filename)
153{
154 char *sysconfdir;
155
156 sysconfdir = getenv("NLSYSCONFDIR");
157
158 if (!sysconfdir)
159 sysconfdir = _NL_SYSCONFDIR_LIBNL;
160
161 return asprintf(strp, "%s/%s", sysconfdir, filename);
162}
163
164/*****************************************************************************/
165
166static inline int rtnl_tc_calc_txtime64(int bufsize, uint64_t rate)
167{
168 return ((double)bufsize / (double)rate) * 1000000.0;
169}
170
171static inline int rtnl_tc_calc_bufsize64(int txtime, uint64_t rate)
172{
173 return ((double)txtime * (double)rate) / 1000000.0;
174}
175
176#endif /* __LIB_ROUTE_NL_ROUTE_H__ */
nh_encap_ops
Definition nexthop-encap.h:4
rtnl_act
Definition nl-route.h:122
rtnl_link_af_ops
Available operations to modules implementing a link address family.
Definition link-api.h:76
rtnl_link_info_ops
Available operations to modules implementing a link info type.
Definition link-api.h:20
rtnl_link_map
Definition nl-route.h:18
rtnl_link_vf
SRIOV VF object.
rtnl_link
Link object.
Definition nl-route.h:29
rtnl_nh_encap
Definition nl-route.h:78
rtnl_qdisc
Definition nl-route.h:118
rtnl_ratespec
Definition nl-route.h:83
rtnl_tc
Definition nl-route.h:114