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