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