netlink-types.h revision 23ee46ef7115c2e311c36e43a833e6c3deada18a
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-2008 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_sock;
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_sock *,
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_sock *,
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_sock *,
55					      struct nl_msg *);
56
57	int			cb_refcnt;
58};
59
60struct nl_sock
61{
62	struct sockaddr_nl	s_local;
63	struct sockaddr_nl	s_peer;
64	int			s_fd;
65	int			s_proto;
66	unsigned int		s_seq_next;
67	unsigned int		s_seq_expect;
68	int			s_flags;
69	struct nl_cb *		s_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_sock *	cm_handle;
93	struct nl_cache_assoc *	cm_assocs;
94};
95
96struct nl_parser_param;
97
98#define LOOSE_COMPARISON	1
99
100#define NL_OBJ_MARK		1
101
102struct nl_object
103{
104	NLHDR_COMMON
105};
106
107struct nl_data
108{
109	size_t			d_size;
110	void *			d_data;
111};
112
113struct nl_addr
114{
115	int			a_family;
116	unsigned int		a_maxsize;
117	unsigned int		a_len;
118	int			a_prefixlen;
119	int			a_refcnt;
120	char			a_addr[0];
121};
122
123struct nl_msg
124{
125	int			nm_protocol;
126	int			nm_flags;
127	struct sockaddr_nl	nm_src;
128	struct sockaddr_nl	nm_dst;
129	struct ucred		nm_creds;
130	struct nlmsghdr *	nm_nlh;
131	size_t			nm_size;
132	int			nm_refcnt;
133};
134
135struct rtnl_link_map
136{
137	uint64_t lm_mem_start;
138	uint64_t lm_mem_end;
139	uint64_t lm_base_addr;
140	uint16_t lm_irq;
141	uint8_t  lm_dma;
142	uint8_t  lm_port;
143};
144
145#define IFQDISCSIZ	32
146
147struct rtnl_link
148{
149	NLHDR_COMMON
150
151	char		l_name[IFNAMSIZ];
152
153	uint32_t	l_family;
154	uint32_t	l_arptype;
155	uint32_t	l_index;
156	uint32_t	l_flags;
157	uint32_t	l_change;
158	uint32_t 	l_mtu;
159	uint32_t	l_link;
160	uint32_t	l_txqlen;
161	uint32_t	l_weight;
162	uint32_t	l_master;
163	struct nl_addr *l_addr;
164	struct nl_addr *l_bcast;
165	char		l_qdisc[IFQDISCSIZ];
166	struct rtnl_link_map l_map;
167	uint64_t	l_stats[RTNL_LINK_STATS_MAX+1];
168	uint32_t	l_flag_mask;
169	uint8_t		l_operstate;
170	uint8_t		l_linkmode;
171	/* 2 byte hole */
172	struct rtnl_link_info_ops *l_info_ops;
173	void *		l_info;
174};
175
176struct rtnl_ncacheinfo
177{
178	uint32_t nci_confirmed;	/**< Time since neighbour validty was last confirmed */
179	uint32_t nci_used;	/**< Time since neighbour entry was last ued */
180	uint32_t nci_updated;	/**< Time since last update */
181	uint32_t nci_refcnt;	/**< Reference counter */
182};
183
184
185struct rtnl_neigh
186{
187	NLHDR_COMMON
188	uint32_t	n_family;
189	uint32_t	n_ifindex;
190	uint16_t	n_state;
191	uint8_t		n_flags;
192	uint8_t		n_type;
193	struct nl_addr *n_lladdr;
194	struct nl_addr *n_dst;
195	uint32_t	n_probes;
196	struct rtnl_ncacheinfo n_cacheinfo;
197	uint32_t                n_state_mask;
198	uint32_t                n_flag_mask;
199};
200
201
202struct rtnl_addr_cacheinfo
203{
204	/* Preferred lifetime in seconds */
205	uint32_t aci_prefered;
206
207	/* Valid lifetime in seconds */
208	uint32_t aci_valid;
209
210	/* Timestamp of creation in 1/100s seince boottime */
211	uint32_t aci_cstamp;
212
213	/* Timestamp of last update in 1/100s since boottime */
214	uint32_t aci_tstamp;
215};
216
217struct rtnl_addr
218{
219	NLHDR_COMMON
220
221	uint8_t		a_family;
222	uint8_t		a_prefixlen;
223	uint8_t		a_flags;
224	uint8_t		a_scope;
225	uint32_t	a_ifindex;
226
227	struct nl_addr *a_peer;
228	struct nl_addr *a_local;
229	struct nl_addr *a_bcast;
230	struct nl_addr *a_anycast;
231	struct nl_addr *a_multicast;
232
233	struct rtnl_addr_cacheinfo a_cacheinfo;
234
235	char a_label[IFNAMSIZ];
236	uint32_t a_flag_mask;
237};
238
239struct rtnl_nexthop
240{
241	uint8_t			rtnh_flags;
242	uint8_t			rtnh_flag_mask;
243	uint8_t			rtnh_weight;
244	/* 1 byte spare */
245	uint32_t		rtnh_ifindex;
246	struct nl_addr *	rtnh_gateway;
247	uint32_t		ce_mask; /* HACK to support attr macros */
248	struct nl_list_head	rtnh_list;
249	uint32_t		rtnh_realms;
250};
251
252struct rtnl_route
253{
254	NLHDR_COMMON
255
256	uint8_t			rt_family;
257	uint8_t			rt_dst_len;
258	uint8_t			rt_src_len;
259	uint8_t			rt_tos;
260	uint8_t			rt_protocol;
261	uint8_t			rt_scope;
262	uint8_t			rt_type;
263	uint8_t			rt_nmetrics;
264	uint32_t		rt_flags;
265	struct nl_addr *	rt_dst;
266	struct nl_addr *	rt_src;
267	uint32_t		rt_table;
268	uint32_t		rt_iif;
269	uint32_t		rt_prio;
270	uint32_t		rt_metrics[RTAX_MAX];
271	uint32_t		rt_metrics_mask;
272	uint32_t		rt_nr_nh;
273	struct nl_addr *	rt_pref_src;
274	struct nl_list_head	rt_nexthops;
275	struct rtnl_rtcacheinfo	rt_cacheinfo;
276	uint32_t		rt_flag_mask;
277};
278
279struct rtnl_rule
280{
281	NLHDR_COMMON
282
283	uint64_t	r_mark;
284	uint32_t	r_prio;
285	uint32_t	r_realms;
286	uint32_t	r_table;
287	uint8_t		r_dsfield;
288	uint8_t		r_type;
289	uint8_t		r_family;
290	uint8_t		r_src_len;
291	uint8_t		r_dst_len;
292	char		r_iif[IFNAMSIZ];
293	struct nl_addr *r_src;
294	struct nl_addr *r_dst;
295	struct nl_addr *r_srcmap;
296};
297
298struct rtnl_neightbl_parms
299{
300	/**
301	 * Interface index of the device this parameter set is assigned
302	 * to or 0 for the default set.
303	 */
304	uint32_t		ntp_ifindex;
305
306	/**
307	 * Number of references to this parameter set.
308	 */
309	uint32_t		ntp_refcnt;
310
311	/**
312	 * Queue length for pending arp requests, i.e. the number of
313	 * packets which are accepted from other layers while the
314	 * neighbour address is still being resolved
315	 */
316	uint32_t		ntp_queue_len;
317
318	/**
319	 * Number of requests to send to the user level ARP daemon.
320	 * Specify 0 to disable.
321	 */
322	uint32_t		ntp_app_probes;
323
324	/**
325	 * Maximum number of retries for unicast solicitation.
326	 */
327	uint32_t		ntp_ucast_probes;
328
329	/**
330	 * Maximum number of retries for multicast solicitation.
331	 */
332	uint32_t		ntp_mcast_probes;
333
334	/**
335	 * Base value in milliseconds to ompute reachable time, see RFC2461.
336	 */
337	uint64_t		ntp_base_reachable_time;
338
339	/**
340	 * Actual reachable time (read-only)
341	 */
342	uint64_t		ntp_reachable_time;	/* secs */
343
344	/**
345	 * The time in milliseconds between retransmitted Neighbor
346	 * Solicitation messages.
347	 */
348	uint64_t		ntp_retrans_time;
349
350	/**
351	 * Interval in milliseconds to check for stale neighbour
352	 * entries.
353	 */
354	uint64_t		ntp_gc_stale_time;	/* secs */
355
356	/**
357	 * Delay in milliseconds for the first time probe if
358	 * the neighbour is reachable.
359	 */
360	uint64_t		ntp_probe_delay;	/* secs */
361
362	/**
363	 * Maximum delay in milliseconds of an answer to a neighbour
364	 * solicitation message.
365	 */
366	uint64_t		ntp_anycast_delay;
367
368	/**
369	 * Minimum age in milliseconds before a neighbour entry
370	 * may be replaced.
371	 */
372	uint64_t		ntp_locktime;
373
374	/**
375	 * Delay in milliseconds before answering to an ARP request
376	 * for which a proxy ARP entry exists.
377	 */
378	uint64_t		ntp_proxy_delay;
379
380	/**
381	 * Queue length for the delayed proxy arp requests.
382	 */
383	uint32_t		ntp_proxy_qlen;
384
385	/**
386	 * Mask of available parameter attributes
387	 */
388	uint32_t		ntp_mask;
389};
390
391#define NTBLNAMSIZ	32
392
393/**
394 * Neighbour table
395 * @ingroup neightbl
396 */
397struct rtnl_neightbl
398{
399	NLHDR_COMMON
400
401	char			nt_name[NTBLNAMSIZ];
402	uint32_t		nt_family;
403	uint32_t		nt_gc_thresh1;
404	uint32_t		nt_gc_thresh2;
405	uint32_t		nt_gc_thresh3;
406	uint64_t		nt_gc_interval;
407	struct ndt_config	nt_config;
408	struct rtnl_neightbl_parms nt_parms;
409	struct ndt_stats	nt_stats;
410};
411
412struct rtnl_ratespec
413{
414	uint8_t			rs_cell_log;
415	uint16_t		rs_feature;
416	uint16_t		rs_addend;
417	uint16_t		rs_mpu;
418	uint32_t		rs_rate;
419};
420
421struct rtnl_tstats
422{
423	struct {
424		uint64_t            bytes;
425		uint64_t            packets;
426	} tcs_basic;
427
428	struct {
429		uint32_t            bps;
430		uint32_t            pps;
431	} tcs_rate_est;
432
433	struct {
434		uint32_t            qlen;
435		uint32_t            backlog;
436		uint32_t            drops;
437		uint32_t            requeues;
438		uint32_t            overlimits;
439	} tcs_queue;
440};
441
442#define TCKINDSIZ	32
443
444#define NL_TCA_GENERIC(pre)				\
445	NLHDR_COMMON					\
446	uint32_t		pre ##_family;		\
447	uint32_t		pre ##_ifindex;		\
448	uint32_t		pre ##_handle;		\
449	uint32_t		pre ##_parent;		\
450	uint32_t		pre ##_info;		\
451	char			pre ##_kind[TCKINDSIZ];	\
452	struct nl_data *	pre ##_opts;		\
453	uint64_t		pre ##_stats[RTNL_TC_STATS_MAX+1]; \
454	struct nl_data *	pre ##_xstats;		\
455	void *			pre ##_subdata;		\
456
457
458struct rtnl_tca
459{
460	NL_TCA_GENERIC(tc);
461};
462
463struct rtnl_qdisc
464{
465	NL_TCA_GENERIC(q);
466	struct rtnl_qdisc_ops	*q_ops;
467};
468
469struct rtnl_class
470{
471	NL_TCA_GENERIC(c);
472	struct rtnl_class_ops	*c_ops;
473};
474
475struct rtnl_cls
476{
477	NL_TCA_GENERIC(c);
478	uint32_t	c_prio;
479	uint32_t	c_protocol;
480	struct rtnl_cls_ops	*c_ops;
481};
482
483struct rtnl_u32
484{
485	uint32_t		cu_divisor;
486	uint32_t		cu_hash;
487	uint32_t		cu_classid;
488	uint32_t		cu_link;
489	struct nl_data *	cu_pcnt;
490	struct nl_data *	cu_selector;
491	struct nl_data *	cu_act;
492	struct nl_data *	cu_police;
493	char			cu_indev[IFNAMSIZ];
494	int			cu_mask;
495};
496
497struct rtnl_fw
498{
499	uint32_t		cf_classid;
500	struct nl_data *	cf_act;
501	struct nl_data *	cf_police;
502	char			cf_indev[IFNAMSIZ];
503	int			cf_mask;
504};
505
506struct rtnl_dsmark_qdisc
507{
508	uint16_t	qdm_indices;
509	uint16_t	qdm_default_index;
510	uint32_t	qdm_set_tc_index;
511	uint32_t	qdm_mask;
512};
513
514struct rtnl_dsmark_class
515{
516	uint8_t		cdm_bmask;
517	uint8_t		cdm_value;
518	uint32_t	cdm_mask;
519};
520
521struct rtnl_fifo
522{
523	uint32_t	qf_limit;
524	uint32_t	qf_mask;
525};
526
527struct rtnl_prio
528{
529	uint32_t	qp_bands;
530	uint8_t		qp_priomap[TC_PRIO_MAX+1];
531	uint32_t	qp_mask;
532};
533
534struct rtnl_tbf
535{
536	uint32_t		qt_limit;
537	uint32_t		qt_mpu;
538	struct rtnl_ratespec	qt_rate;
539	uint32_t		qt_rate_bucket;
540	uint32_t		qt_rate_txtime;
541	struct rtnl_ratespec	qt_peakrate;
542	uint32_t		qt_peakrate_bucket;
543	uint32_t		qt_peakrate_txtime;
544	uint32_t		qt_mask;
545};
546
547struct rtnl_sfq
548{
549	uint32_t	qs_quantum;
550	uint32_t	qs_perturb;
551	uint32_t	qs_limit;
552	uint32_t	qs_divisor;
553	uint32_t	qs_flows;
554	uint32_t	qs_mask;
555};
556
557struct rtnl_netem_corr
558{
559	uint32_t	nmc_delay;
560	uint32_t	nmc_loss;
561	uint32_t	nmc_duplicate;
562};
563
564struct rtnl_netem_reo
565{
566	uint32_t	nmro_probability;
567	uint32_t	nmro_correlation;
568};
569
570struct rtnl_netem_crpt
571{
572	uint32_t	nmcr_probability;
573	uint32_t	nmcr_correlation;
574};
575
576struct rtnl_netem_dist
577{
578	int16_t	*	dist_data;
579	size_t		dist_size;
580};
581
582struct rtnl_netem
583{
584	uint32_t		qnm_latency;
585	uint32_t		qnm_limit;
586	uint32_t		qnm_loss;
587	uint32_t		qnm_gap;
588	uint32_t		qnm_duplicate;
589	uint32_t		qnm_jitter;
590	uint32_t		qnm_mask;
591	struct rtnl_netem_corr	qnm_corr;
592	struct rtnl_netem_reo	qnm_ro;
593	struct rtnl_netem_crpt	qnm_crpt;
594	struct rtnl_netem_dist  qnm_dist;
595};
596
597struct rtnl_htb_qdisc
598{
599	uint32_t		qh_rate2quantum;
600	uint32_t		qh_defcls;
601	uint32_t		qh_mask;
602};
603
604struct rtnl_htb_class
605{
606	uint32_t		ch_prio;
607	uint32_t		ch_mtu;
608	struct rtnl_ratespec	ch_rate;
609	struct rtnl_ratespec	ch_ceil;
610	uint32_t		ch_rbuffer;
611	uint32_t		ch_cbuffer;
612	uint32_t		ch_quantum;
613	uint8_t			ch_overhead;
614	uint8_t			ch_mpu;
615	uint32_t		ch_mask;
616};
617
618struct rtnl_cbq
619{
620	struct tc_cbq_lssopt    cbq_lss;
621	struct tc_ratespec      cbq_rate;
622	struct tc_cbq_wrropt    cbq_wrr;
623	struct tc_cbq_ovl       cbq_ovl;
624	struct tc_cbq_fopt      cbq_fopt;
625	struct tc_cbq_police    cbq_police;
626};
627
628struct rtnl_red
629{
630	uint32_t	qr_limit;
631	uint32_t	qr_qth_min;
632	uint32_t	qr_qth_max;
633	uint8_t		qr_flags;
634	uint8_t		qr_wlog;
635	uint8_t		qr_plog;
636	uint8_t		qr_scell_log;
637	uint32_t	qr_mask;
638};
639
640struct flnl_request
641{
642	NLHDR_COMMON
643
644	struct nl_addr *	lr_addr;
645	uint32_t		lr_fwmark;
646	uint8_t			lr_tos;
647	uint8_t			lr_scope;
648	uint8_t			lr_table;
649};
650
651
652struct flnl_result
653{
654	NLHDR_COMMON
655
656	struct flnl_request *	fr_req;
657	uint8_t			fr_table_id;
658	uint8_t			fr_prefixlen;
659	uint8_t			fr_nh_sel;
660	uint8_t			fr_type;
661	uint8_t			fr_scope;
662	uint32_t		fr_error;
663};
664
665#define GENL_OP_HAS_POLICY	1
666#define GENL_OP_HAS_DOIT	2
667#define GENL_OP_HAS_DUMPIT	4
668
669struct genl_family_op
670{
671	uint32_t		o_id;
672	uint32_t		o_flags;
673
674	struct nl_list_head	o_list;
675};
676
677struct genl_family
678{
679	NLHDR_COMMON
680
681	uint16_t		gf_id;
682	char 			gf_name[GENL_NAMSIZ];
683	uint32_t		gf_version;
684	uint32_t		gf_hdrsize;
685	uint32_t		gf_maxattr;
686
687	struct nl_list_head	gf_ops;
688};
689
690union nfnl_ct_proto
691{
692	struct {
693		uint16_t	src;
694		uint16_t	dst;
695	} port;
696	struct {
697		uint16_t	id;
698		uint8_t		type;
699		uint8_t		code;
700	} icmp;
701};
702
703struct nfnl_ct_dir {
704	struct nl_addr *	src;
705	struct nl_addr *	dst;
706	union nfnl_ct_proto	proto;
707	uint64_t		packets;
708	uint64_t		bytes;
709};
710
711union nfnl_ct_protoinfo {
712	struct {
713		uint8_t		state;
714	} tcp;
715};
716
717struct nfnl_ct {
718	NLHDR_COMMON
719
720	uint8_t			ct_family;
721	uint8_t			ct_proto;
722	union nfnl_ct_protoinfo	ct_protoinfo;
723
724	uint32_t		ct_status;
725	uint32_t		ct_status_mask;
726	uint32_t		ct_timeout;
727	uint32_t		ct_mark;
728	uint32_t		ct_use;
729	uint32_t		ct_id;
730
731	struct nfnl_ct_dir	ct_orig;
732	struct nfnl_ct_dir	ct_repl;
733};
734
735struct nfnl_log {
736	NLHDR_COMMON
737
738	uint16_t		log_group;
739	uint8_t			log_copy_mode;
740	uint32_t		log_copy_range;
741	uint32_t		log_flush_timeout;
742	uint32_t		log_alloc_size;
743	uint32_t		log_queue_threshold;
744	uint32_t		log_flags;
745	uint32_t		log_flag_mask;
746};
747
748struct nfnl_log_msg {
749	NLHDR_COMMON
750
751	uint8_t			log_msg_family;
752	uint8_t			log_msg_hook;
753	uint16_t		log_msg_hwproto;
754	uint32_t		log_msg_mark;
755	struct timeval		log_msg_timestamp;
756	uint32_t		log_msg_indev;
757	uint32_t		log_msg_outdev;
758	uint32_t		log_msg_physindev;
759	uint32_t		log_msg_physoutdev;
760	uint8_t			log_msg_hwaddr[8];
761	int			log_msg_hwaddr_len;
762	void *			log_msg_payload;
763	int			log_msg_payload_len;
764	char *			log_msg_prefix;
765	uint32_t		log_msg_uid;
766	uint32_t		log_msg_gid;
767	uint32_t		log_msg_seq;
768	uint32_t		log_msg_seq_global;
769};
770
771struct nfnl_queue {
772	NLHDR_COMMON
773
774	uint16_t		queue_group;
775	uint32_t		queue_maxlen;
776	uint32_t		queue_copy_range;
777	uint8_t			queue_copy_mode;
778};
779
780struct nfnl_queue_msg {
781	NLHDR_COMMON
782
783	uint16_t		queue_msg_group;
784	uint8_t			queue_msg_family;
785	uint8_t			queue_msg_hook;
786	uint16_t		queue_msg_hwproto;
787	uint32_t		queue_msg_packetid;
788	uint32_t		queue_msg_mark;
789	struct timeval		queue_msg_timestamp;
790	uint32_t		queue_msg_indev;
791	uint32_t		queue_msg_outdev;
792	uint32_t		queue_msg_physindev;
793	uint32_t		queue_msg_physoutdev;
794	uint8_t			queue_msg_hwaddr[8];
795	int			queue_msg_hwaddr_len;
796	void *			queue_msg_payload;
797	int			queue_msg_payload_len;
798	uint32_t		queue_msg_verdict;
799};
800
801#endif
802