netlink-types.h revision 535e83162249ed6274ba46bc72d8cc683ba20e17
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_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_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
579{
580	uint32_t		qnm_latency;
581	uint32_t		qnm_limit;
582	uint32_t		qnm_loss;
583	uint32_t		qnm_gap;
584	uint32_t		qnm_duplicate;
585	uint32_t		qnm_jitter;
586	uint32_t		qnm_mask;
587	struct rtnl_netem_corr	qnm_corr;
588	struct rtnl_netem_reo	qnm_ro;
589};
590
591struct rtnl_htb_qdisc
592{
593	uint32_t		qh_rate2quantum;
594	uint32_t		qh_defcls;
595	uint32_t		qh_mask;
596};
597
598struct rtnl_htb_class
599{
600	uint32_t		ch_prio;
601	uint32_t		ch_mtu;
602	struct rtnl_ratespec	ch_rate;
603	struct rtnl_ratespec	ch_ceil;
604	uint32_t		ch_rbuffer;
605	uint32_t		ch_cbuffer;
606	uint32_t		ch_quantum;
607	uint8_t			ch_overhead;
608	uint8_t			ch_mpu;
609	uint32_t		ch_mask;
610};
611
612struct rtnl_cbq
613{
614	struct tc_cbq_lssopt    cbq_lss;
615	struct tc_ratespec      cbq_rate;
616	struct tc_cbq_wrropt    cbq_wrr;
617	struct tc_cbq_ovl       cbq_ovl;
618	struct tc_cbq_fopt      cbq_fopt;
619	struct tc_cbq_police    cbq_police;
620};
621
622struct rtnl_red
623{
624	uint32_t	qr_limit;
625	uint32_t	qr_qth_min;
626	uint32_t	qr_qth_max;
627	uint8_t		qr_flags;
628	uint8_t		qr_wlog;
629	uint8_t		qr_plog;
630	uint8_t		qr_scell_log;
631	uint32_t	qr_mask;
632};
633
634struct flnl_request
635{
636	NLHDR_COMMON
637
638	struct nl_addr *	lr_addr;
639	uint32_t		lr_fwmark;
640	uint8_t			lr_tos;
641	uint8_t			lr_scope;
642	uint8_t			lr_table;
643};
644
645
646struct flnl_result
647{
648	NLHDR_COMMON
649
650	struct flnl_request *	fr_req;
651	uint8_t			fr_table_id;
652	uint8_t			fr_prefixlen;
653	uint8_t			fr_nh_sel;
654	uint8_t			fr_type;
655	uint8_t			fr_scope;
656	uint32_t		fr_error;
657};
658
659#define GENL_OP_HAS_POLICY	1
660#define GENL_OP_HAS_DOIT	2
661#define GENL_OP_HAS_DUMPIT	4
662
663struct genl_family_op
664{
665	uint32_t		o_id;
666	uint32_t		o_flags;
667
668	struct nl_list_head	o_list;
669};
670
671struct genl_family
672{
673	NLHDR_COMMON
674
675	uint16_t		gf_id;
676	char 			gf_name[GENL_NAMSIZ];
677	uint32_t		gf_version;
678	uint32_t		gf_hdrsize;
679	uint32_t		gf_maxattr;
680
681	struct nl_list_head	gf_ops;
682};
683
684union nfnl_ct_proto
685{
686	struct {
687		uint16_t	src;
688		uint16_t	dst;
689	} port;
690	struct {
691		uint16_t	id;
692		uint8_t		type;
693		uint8_t		code;
694	} icmp;
695};
696
697struct nfnl_ct_dir {
698	struct nl_addr *	src;
699	struct nl_addr *	dst;
700	union nfnl_ct_proto	proto;
701	uint64_t		packets;
702	uint64_t		bytes;
703};
704
705union nfnl_ct_protoinfo {
706	struct {
707		uint8_t		state;
708	} tcp;
709};
710
711struct nfnl_ct {
712	NLHDR_COMMON
713
714	uint8_t			ct_family;
715	uint8_t			ct_proto;
716	union nfnl_ct_protoinfo	ct_protoinfo;
717
718	uint32_t		ct_status;
719	uint32_t		ct_status_mask;
720	uint32_t		ct_timeout;
721	uint32_t		ct_mark;
722	uint32_t		ct_use;
723	uint32_t		ct_id;
724
725	struct nfnl_ct_dir	ct_orig;
726	struct nfnl_ct_dir	ct_repl;
727};
728
729struct nfnl_log {
730	NLHDR_COMMON
731
732	uint16_t		log_group;
733	uint8_t			log_copy_mode;
734	uint32_t		log_copy_range;
735	uint32_t		log_flush_timeout;
736	uint32_t		log_alloc_size;
737	uint32_t		log_queue_threshold;
738	uint32_t		log_flags;
739	uint32_t		log_flag_mask;
740};
741
742struct nfnl_log_msg {
743	NLHDR_COMMON
744
745	uint8_t			log_msg_family;
746	uint8_t			log_msg_hook;
747	uint16_t		log_msg_hwproto;
748	uint32_t		log_msg_mark;
749	struct timeval		log_msg_timestamp;
750	uint32_t		log_msg_indev;
751	uint32_t		log_msg_outdev;
752	uint32_t		log_msg_physindev;
753	uint32_t		log_msg_physoutdev;
754	uint8_t			log_msg_hwaddr[8];
755	int			log_msg_hwaddr_len;
756	void *			log_msg_payload;
757	int			log_msg_payload_len;
758	char *			log_msg_prefix;
759	uint32_t		log_msg_uid;
760	uint32_t		log_msg_gid;
761	uint32_t		log_msg_seq;
762	uint32_t		log_msg_seq_global;
763};
764
765struct nfnl_queue {
766	NLHDR_COMMON
767
768	uint16_t		queue_group;
769	uint32_t		queue_maxlen;
770	uint32_t		queue_copy_range;
771	uint8_t			queue_copy_mode;
772};
773
774struct nfnl_queue_msg {
775	NLHDR_COMMON
776
777	uint16_t		queue_msg_group;
778	uint8_t			queue_msg_family;
779	uint8_t			queue_msg_hook;
780	uint16_t		queue_msg_hwproto;
781	uint32_t		queue_msg_packetid;
782	uint32_t		queue_msg_mark;
783	struct timeval		queue_msg_timestamp;
784	uint32_t		queue_msg_indev;
785	uint32_t		queue_msg_outdev;
786	uint32_t		queue_msg_physindev;
787	uint32_t		queue_msg_physoutdev;
788	uint8_t			queue_msg_hwaddr[8];
789	int			queue_msg_hwaddr_len;
790	void *			queue_msg_payload;
791	int			queue_msg_payload_len;
792	uint32_t		queue_msg_verdict;
793};
794
795#endif
796