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