netlink-types.h revision 3ad4665be2f192291238cbe78118a57ec42436c6
1/*
2 * netlink-types.h	Netlink Types (Private)
3 *
4 *	This library is free software; you can redistribute it and/or
5 *	modify it under the terms of the GNU Lesser General Public
6 *	License as published by the Free Software Foundation version 2.1
7 *	of the License.
8 *
9 * Copyright (c) 2003-2006 Thomas Graf <tgraf@suug.ch>
10 */
11
12#ifndef NETLINK_LOCAL_TYPES_H_
13#define NETLINK_LOCAL_TYPES_H_
14
15#include <netlink/list.h>
16#include <netlink/route/link.h>
17#include <netlink/route/qdisc.h>
18#include <netlink/route/rtnl.h>
19#include <netlink/route/route.h>
20
21#define NL_SOCK_BUFSIZE_SET	(1<<0)
22#define NL_SOCK_PASSCRED	(1<<1)
23#define NL_OWN_PORT		(1<<2)
24#define NL_MSG_PEEK		(1<<3)
25
26#define NL_MSG_CRED_PRESENT 1
27
28struct nl_cache_ops;
29struct nl_handle;
30struct nl_object;
31
32struct nl_cb
33{
34	nl_recvmsg_msg_cb_t	cb_set[NL_CB_TYPE_MAX+1];
35	void *			cb_args[NL_CB_TYPE_MAX+1];
36
37	nl_recvmsg_err_cb_t	cb_err;
38	void *			cb_err_arg;
39
40	/** May be used to replace nl_recvmsgs with your own implementation
41	 * in all internal calls to nl_recvmsgs. */
42	int			(*cb_recvmsgs_ow)(struct nl_handle *,
43						  struct nl_cb *);
44
45	/** Overwrite internal calls to nl_recv, must return the number of
46	 * octets read and allocate a buffer for the received data. */
47	int			(*cb_recv_ow)(struct nl_handle *,
48					      struct sockaddr_nl *,
49					      unsigned char **,
50					      struct ucred **);
51
52	/** Overwrites internal calls to nl_send, must send the netlink
53	 * message. */
54	int			(*cb_send_ow)(struct nl_handle *,
55					      struct nl_msg *);
56
57	int			cb_refcnt;
58};
59
60struct nl_handle
61{
62	struct sockaddr_nl	h_local;
63	struct sockaddr_nl	h_peer;
64	int			h_fd;
65	int			h_proto;
66	unsigned int		h_seq_next;
67	unsigned int		h_seq_expect;
68	int			h_flags;
69	struct nl_cb *		h_cb;
70};
71
72struct nl_cache
73{
74	struct nl_list_head	c_items;
75	int			c_nitems;
76	int                     c_iarg1;
77	int                     c_iarg2;
78	struct nl_cache_ops *   c_ops;
79};
80
81struct nl_cache_assoc
82{
83	struct nl_cache *	ca_cache;
84	change_func_t		ca_change;
85};
86
87struct nl_cache_mngr
88{
89	int			cm_protocol;
90	int			cm_flags;
91	int			cm_nassocs;
92	struct nl_handle *	cm_handle;
93	struct nl_cache_assoc *	cm_assocs;
94};
95
96struct nl_parser_param;
97
98struct genl_info
99{
100	struct sockaddr_nl *	who;
101	struct nlmsghdr *	nlh;
102	struct genlmsghdr *	genlhdr;
103	void *			userhdr;
104	struct nlattr **	attrs;
105};
106
107#define LOOSE_FLAG_COMPARISON	1
108
109#define NL_OBJ_MARK		1
110
111struct nl_object
112{
113	NLHDR_COMMON
114};
115
116struct nl_data
117{
118	size_t			d_size;
119	void *			d_data;
120};
121
122struct nl_addr
123{
124	int			a_family;
125	unsigned int		a_maxsize;
126	unsigned int		a_len;
127	int			a_prefixlen;
128	int			a_refcnt;
129	char			a_addr[0];
130};
131
132struct nl_msg
133{
134	int			nm_protocol;
135	int			nm_flags;
136	struct sockaddr_nl	nm_src;
137	struct sockaddr_nl	nm_dst;
138	struct ucred		nm_creds;
139	struct nlmsghdr *	nm_nlh;
140};
141
142struct rtnl_link_map
143{
144	uint64_t lm_mem_start;
145	uint64_t lm_mem_end;
146	uint64_t lm_base_addr;
147	uint16_t lm_irq;
148	uint8_t  lm_dma;
149	uint8_t  lm_port;
150};
151
152#define IFQDISCSIZ	32
153
154struct rtnl_link
155{
156	NLHDR_COMMON
157
158	char		l_name[IFNAMSIZ];
159
160	uint32_t	l_family;
161	uint32_t	l_arptype;
162	uint32_t	l_index;
163	uint32_t	l_flags;
164	uint32_t	l_change;
165	uint32_t 	l_mtu;
166	uint32_t	l_link;
167	uint32_t	l_txqlen;
168	uint32_t	l_weight;
169	uint32_t	l_master;
170	struct nl_addr *l_addr;
171	struct nl_addr *l_bcast;
172	char		l_qdisc[IFQDISCSIZ];
173	struct rtnl_link_map l_map;
174	uint64_t	l_stats[RTNL_LINK_STATS_MAX+1];
175	uint32_t	l_flag_mask;
176	uint8_t		l_operstate;
177	uint8_t		l_linkmode;
178};
179
180struct rtnl_ncacheinfo
181{
182	uint32_t nci_confirmed;	/**< Time since neighbour validty was last confirmed */
183	uint32_t nci_used;	/**< Time since neighbour entry was last ued */
184	uint32_t nci_updated;	/**< Time since last update */
185	uint32_t nci_refcnt;	/**< Reference counter */
186};
187
188
189struct rtnl_neigh
190{
191	NLHDR_COMMON
192	uint32_t	n_family;
193	uint32_t	n_ifindex;
194	uint16_t	n_state;
195	uint8_t		n_flags;
196	uint8_t		n_type;
197	struct nl_addr *n_lladdr;
198	struct nl_addr *n_dst;
199	uint32_t	n_probes;
200	struct rtnl_ncacheinfo n_cacheinfo;
201	uint32_t                n_state_mask;
202	uint32_t                n_flag_mask;
203};
204
205
206struct rtnl_addr_cacheinfo
207{
208	/* Preferred lifetime in seconds */
209	uint32_t aci_prefered;
210
211	/* Valid lifetime in seconds */
212	uint32_t aci_valid;
213
214	/* Timestamp of creation in 1/100s seince boottime */
215	uint32_t aci_cstamp;
216
217	/* Timestamp of last update in 1/100s since boottime */
218	uint32_t aci_tstamp;
219};
220
221struct rtnl_addr
222{
223	NLHDR_COMMON
224
225	uint8_t		a_family;
226	uint8_t		a_prefixlen;
227	uint8_t		a_flags;
228	uint8_t		a_scope;
229	uint32_t	a_ifindex;
230
231	struct nl_addr *a_peer;
232	struct nl_addr *a_local;
233	struct nl_addr *a_bcast;
234	struct nl_addr *a_anycast;
235	struct nl_addr *a_multicast;
236
237	struct rtnl_addr_cacheinfo a_cacheinfo;
238
239	char a_label[IFNAMSIZ];
240	uint32_t a_flag_mask;
241};
242
243#define NEXTHOP_HAS_FLAGS   0x000001
244#define NEXTHOP_HAS_WEIGHT  0x000002
245#define NEXTHOP_HAS_IFINDEX 0x000004
246#define NEXTHOP_HAS_GATEWAY 0x000008
247
248struct rtnl_nexthop
249{
250	uint8_t			rtnh_flags;
251	uint8_t			rtnh_flag_mask;
252	uint8_t			rtnh_weight;
253	/* 1 byte spare */
254	uint32_t		rtnh_ifindex;
255	struct nl_addr *	rtnh_gateway;
256	uint32_t		rtnh_mask;
257
258	struct nl_list_head	rtnh_list;
259};
260
261struct rtnl_route
262{
263	NLHDR_COMMON
264
265	uint8_t			rt_family;
266	uint8_t			rt_dst_len;
267	uint8_t			rt_src_len;
268	uint8_t			rt_tos;
269	uint8_t			rt_table;
270	uint8_t			rt_protocol;
271	uint8_t			rt_scope;
272	uint8_t			rt_type;
273	uint32_t		rt_flags;
274	struct nl_addr *	rt_dst;
275	struct nl_addr *	rt_src;
276	char			rt_iif[IFNAMSIZ];
277	uint32_t		rt_oif;
278	struct nl_addr *	rt_gateway;
279	uint32_t		rt_prio;
280	uint32_t		rt_metrics[RTAX_MAX];
281	uint32_t		rt_metrics_mask;
282	struct nl_addr *	rt_pref_src;
283	struct nl_list_head	rt_nexthops;
284	realm_t			rt_realms;
285	struct rtnl_rtcacheinfo	rt_cacheinfo;
286	uint32_t		rt_mp_algo;
287	uint32_t		rt_flag_mask;
288};
289
290struct rtnl_rule
291{
292	NLHDR_COMMON
293
294	uint64_t	r_mark;
295	uint32_t	r_prio;
296	uint32_t	r_realms;
297	uint32_t	r_table;
298	uint8_t		r_dsfield;
299	uint8_t		r_type;
300	uint8_t		r_family;
301	uint8_t		r_src_len;
302	uint8_t		r_dst_len;
303	char		r_iif[IFNAMSIZ];
304	struct nl_addr *r_src;
305	struct nl_addr *r_dst;
306	struct nl_addr *r_srcmap;
307};
308
309struct rtnl_neightbl_parms
310{
311	/**
312	 * Interface index of the device this parameter set is assigned
313	 * to or 0 for the default set.
314	 */
315	uint32_t		ntp_ifindex;
316
317	/**
318	 * Number of references to this parameter set.
319	 */
320	uint32_t		ntp_refcnt;
321
322	/**
323	 * Queue length for pending arp requests, i.e. the number of
324	 * packets which are accepted from other layers while the
325	 * neighbour address is still being resolved
326	 */
327	uint32_t		ntp_queue_len;
328
329	/**
330	 * Number of requests to send to the user level ARP daemon.
331	 * Specify 0 to disable.
332	 */
333	uint32_t		ntp_app_probes;
334
335	/**
336	 * Maximum number of retries for unicast solicitation.
337	 */
338	uint32_t		ntp_ucast_probes;
339
340	/**
341	 * Maximum number of retries for multicast solicitation.
342	 */
343	uint32_t		ntp_mcast_probes;
344
345	/**
346	 * Base value in milliseconds to ompute reachable time, see RFC2461.
347	 */
348	uint64_t		ntp_base_reachable_time;
349
350	/**
351	 * Actual reachable time (read-only)
352	 */
353	uint64_t		ntp_reachable_time;	/* secs */
354
355	/**
356	 * The time in milliseconds between retransmitted Neighbor
357	 * Solicitation messages.
358	 */
359	uint64_t		ntp_retrans_time;
360
361	/**
362	 * Interval in milliseconds to check for stale neighbour
363	 * entries.
364	 */
365	uint64_t		ntp_gc_stale_time;	/* secs */
366
367	/**
368	 * Delay in milliseconds for the first time probe if
369	 * the neighbour is reachable.
370	 */
371	uint64_t		ntp_probe_delay;	/* secs */
372
373	/**
374	 * Maximum delay in milliseconds of an answer to a neighbour
375	 * solicitation message.
376	 */
377	uint64_t		ntp_anycast_delay;
378
379	/**
380	 * Minimum age in milliseconds before a neighbour entry
381	 * may be replaced.
382	 */
383	uint64_t		ntp_locktime;
384
385	/**
386	 * Delay in milliseconds before answering to an ARP request
387	 * for which a proxy ARP entry exists.
388	 */
389	uint64_t		ntp_proxy_delay;
390
391	/**
392	 * Queue length for the delayed proxy arp requests.
393	 */
394	uint32_t		ntp_proxy_qlen;
395
396	/**
397	 * Mask of available parameter attributes
398	 */
399	uint32_t		ntp_mask;
400};
401
402#define NTBLNAMSIZ	32
403
404/**
405 * Neighbour table
406 * @ingroup neightbl
407 */
408struct rtnl_neightbl
409{
410	NLHDR_COMMON
411
412	char			nt_name[NTBLNAMSIZ];
413	uint32_t		nt_family;
414	uint32_t		nt_gc_thresh1;
415	uint32_t		nt_gc_thresh2;
416	uint32_t		nt_gc_thresh3;
417	uint64_t		nt_gc_interval;
418	struct ndt_config	nt_config;
419	struct rtnl_neightbl_parms nt_parms;
420	struct ndt_stats	nt_stats;
421};
422
423struct rtnl_ratespec
424{
425	uint8_t			rs_cell_log;
426	uint16_t		rs_feature;
427	uint16_t		rs_addend;
428	uint16_t		rs_mpu;
429	uint32_t		rs_rate;
430};
431
432struct rtnl_tstats
433{
434	struct {
435		uint64_t            bytes;
436		uint64_t            packets;
437	} tcs_basic;
438
439	struct {
440		uint32_t            bps;
441		uint32_t            pps;
442	} tcs_rate_est;
443
444	struct {
445		uint32_t            qlen;
446		uint32_t            backlog;
447		uint32_t            drops;
448		uint32_t            requeues;
449		uint32_t            overlimits;
450	} tcs_queue;
451};
452
453#define TCKINDSIZ	32
454
455#define NL_TCA_GENERIC(pre)				\
456	NLHDR_COMMON					\
457	uint32_t		pre ##_family;		\
458	uint32_t		pre ##_ifindex;		\
459	uint32_t		pre ##_handle;		\
460	uint32_t		pre ##_parent;		\
461	uint32_t		pre ##_info;		\
462	char			pre ##_kind[TCKINDSIZ];	\
463	struct nl_data *	pre ##_opts;		\
464	uint64_t		pre ##_stats[RTNL_TC_STATS_MAX+1]; \
465	struct nl_data *	pre ##_xstats;		\
466	void *			pre ##_subdata;		\
467
468
469struct rtnl_tca
470{
471	NL_TCA_GENERIC(tc);
472};
473
474struct rtnl_qdisc
475{
476	NL_TCA_GENERIC(q);
477	struct rtnl_qdisc_ops	*q_ops;
478};
479
480struct rtnl_class
481{
482	NL_TCA_GENERIC(c);
483	struct rtnl_class_ops	*c_ops;
484};
485
486struct rtnl_cls
487{
488	NL_TCA_GENERIC(c);
489	uint32_t	c_prio;
490	uint32_t	c_protocol;
491	struct rtnl_cls_ops	*c_ops;
492};
493
494struct rtnl_u32
495{
496	uint32_t		cu_divisor;
497	uint32_t		cu_hash;
498	uint32_t		cu_classid;
499	uint32_t		cu_link;
500	struct nl_data *	cu_pcnt;
501	struct nl_data *	cu_selector;
502	struct nl_data *	cu_act;
503	struct nl_data *	cu_police;
504	char			cu_indev[IFNAMSIZ];
505	int			cu_mask;
506};
507
508struct rtnl_fw
509{
510	uint32_t		cf_classid;
511	struct nl_data *	cf_act;
512	struct nl_data *	cf_police;
513	char			cf_indev[IFNAMSIZ];
514	int			cf_mask;
515};
516
517struct rtnl_dsmark_qdisc
518{
519	uint16_t	qdm_indices;
520	uint16_t	qdm_default_index;
521	uint32_t	qdm_set_tc_index;
522	uint32_t	qdm_mask;
523};
524
525struct rtnl_dsmark_class
526{
527	uint8_t		cdm_bmask;
528	uint8_t		cdm_value;
529	uint32_t	cdm_mask;
530};
531
532struct rtnl_fifo
533{
534	uint32_t	qf_limit;
535	uint32_t	qf_mask;
536};
537
538struct rtnl_prio
539{
540	uint32_t	qp_bands;
541	uint8_t		qp_priomap[TC_PRIO_MAX+1];
542	uint32_t	qp_mask;
543};
544
545struct rtnl_tbf
546{
547	uint32_t		qt_limit;
548	uint32_t		qt_mpu;
549	struct rtnl_ratespec	qt_rate;
550	uint32_t		qt_rate_bucket;
551	uint32_t		qt_rate_txtime;
552	struct rtnl_ratespec	qt_peakrate;
553	uint32_t		qt_peakrate_bucket;
554	uint32_t		qt_peakrate_txtime;
555	uint32_t		qt_mask;
556};
557
558struct rtnl_sfq
559{
560	uint32_t	qs_quantum;
561	uint32_t	qs_perturb;
562	uint32_t	qs_limit;
563	uint32_t	qs_divisor;
564	uint32_t	qs_flows;
565	uint32_t	qs_mask;
566};
567
568struct rtnl_netem_corr
569{
570	uint32_t	nmc_delay;
571	uint32_t	nmc_loss;
572	uint32_t	nmc_duplicate;
573};
574
575struct rtnl_netem_reo
576{
577	uint32_t	nmro_probability;
578	uint32_t	nmro_correlation;
579};
580
581struct rtnl_netem
582{
583	uint32_t		qnm_latency;
584	uint32_t		qnm_limit;
585	uint32_t		qnm_loss;
586	uint32_t		qnm_gap;
587	uint32_t		qnm_duplicate;
588	uint32_t		qnm_jitter;
589	uint32_t		qnm_mask;
590	struct rtnl_netem_corr	qnm_corr;
591	struct rtnl_netem_reo	qnm_ro;
592};
593
594struct rtnl_htb_qdisc
595{
596	uint32_t		qh_rate2quantum;
597	uint32_t		qh_defcls;
598	uint32_t		qh_mask;
599};
600
601struct rtnl_htb_class
602{
603	uint32_t		ch_prio;
604	uint32_t		ch_mtu;
605	struct rtnl_ratespec	ch_rate;
606	struct rtnl_ratespec	ch_ceil;
607	uint32_t		ch_rbuffer;
608	uint32_t		ch_cbuffer;
609	uint32_t		ch_quantum;
610	uint8_t			ch_overhead;
611	uint8_t			ch_mpu;
612	uint32_t		ch_mask;
613};
614
615struct rtnl_cbq
616{
617	struct tc_cbq_lssopt    cbq_lss;
618	struct tc_ratespec      cbq_rate;
619	struct tc_cbq_wrropt    cbq_wrr;
620	struct tc_cbq_ovl       cbq_ovl;
621	struct tc_cbq_fopt      cbq_fopt;
622	struct tc_cbq_police    cbq_police;
623};
624
625struct rtnl_red
626{
627	uint32_t	qr_limit;
628	uint32_t	qr_qth_min;
629	uint32_t	qr_qth_max;
630	uint8_t		qr_flags;
631	uint8_t		qr_wlog;
632	uint8_t		qr_plog;
633	uint8_t		qr_scell_log;
634	uint32_t	qr_mask;
635};
636
637struct flnl_request
638{
639	NLHDR_COMMON
640
641	struct nl_addr *	lr_addr;
642	uint32_t		lr_fwmark;
643	uint8_t			lr_tos;
644	uint8_t			lr_scope;
645	uint8_t			lr_table;
646};
647
648
649struct flnl_result
650{
651	NLHDR_COMMON
652
653	struct flnl_request *	fr_req;
654	uint8_t			fr_table_id;
655	uint8_t			fr_prefixlen;
656	uint8_t			fr_nh_sel;
657	uint8_t			fr_type;
658	uint8_t			fr_scope;
659	uint32_t		fr_error;
660};
661
662#define GENL_OP_HAS_POLICY	1
663#define GENL_OP_HAS_DOIT	2
664#define GENL_OP_HAS_DUMPIT	4
665
666struct genl_family_op
667{
668	uint32_t		o_id;
669	uint32_t		o_flags;
670
671	struct nl_list_head	o_list;
672};
673
674struct genl_family
675{
676	NLHDR_COMMON
677
678	uint16_t		gf_id;
679	char 			gf_name[GENL_NAMSIZ];
680	uint32_t		gf_version;
681	uint32_t		gf_hdrsize;
682	uint32_t		gf_maxattr;
683
684	struct nl_list_head	gf_ops;
685};
686
687union nfnl_ct_proto
688{
689	struct {
690		uint16_t	src;
691		uint16_t	dst;
692	} port;
693	struct {
694		uint16_t	id;
695		uint8_t		type;
696		uint8_t		code;
697	} icmp;
698};
699
700struct nfnl_ct_dir {
701	struct nl_addr *	src;
702	struct nl_addr *	dst;
703	union nfnl_ct_proto	proto;
704	uint64_t		packets;
705	uint64_t		bytes;
706};
707
708union nfnl_ct_protoinfo {
709	struct {
710		uint8_t		state;
711	} tcp;
712};
713
714struct nfnl_ct {
715	NLHDR_COMMON
716
717	uint8_t			ct_family;
718	uint8_t			ct_proto;
719	union nfnl_ct_protoinfo	ct_protoinfo;
720
721	uint32_t		ct_status;
722	uint32_t		ct_status_mask;
723	uint32_t		ct_timeout;
724	uint32_t		ct_mark;
725	uint32_t		ct_use;
726	uint32_t		ct_id;
727
728	struct nfnl_ct_dir	ct_orig;
729	struct nfnl_ct_dir	ct_repl;
730};
731
732struct nfnl_log {
733	NLHDR_COMMON
734
735	uint8_t			log_family;
736	uint8_t			log_hook;
737	uint16_t		log_hwproto;
738	uint32_t		log_mark;
739	struct timeval		log_timestamp;
740	uint32_t		log_indev;
741	uint32_t		log_outdev;
742	uint32_t		log_physindev;
743	uint32_t		log_physoutdev;
744	uint8_t			log_hwaddr[8];
745	int			log_hwaddr_len;
746	void *			log_payload;
747	int			log_payload_len;
748	char *			log_prefix;
749	uint32_t		log_uid;
750	uint32_t		log_seq;
751	uint32_t		log_seq_global;
752};
753
754#endif
755