netlink-types.h revision 3040a1d6254465bed9e44e4d1bf279c2c50cd16a
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-2006 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_FLAG_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};
141
142struct rtnl_link_map
143{
144	uint64_t lm_mem_start;
145	uint64_t lm_mem_end;
146	uint64_t lm_base_addr;
147	uint16_t lm_irq;
148	uint8_t  lm_dma;
149	uint8_t  lm_port;
150};
151
152#define IFQDISCSIZ	32
153
154struct rtnl_link
155{
156	NLHDR_COMMON
157
158	char		l_name[IFNAMSIZ];
159
160	uint32_t	l_family;
161	uint32_t	l_arptype;
162	uint32_t	l_index;
163	uint32_t	l_flags;
164	uint32_t	l_change;
165	uint32_t 	l_mtu;
166	uint32_t	l_link;
167	uint32_t	l_txqlen;
168	uint32_t	l_weight;
169	uint32_t	l_master;
170	struct nl_addr *l_addr;
171	struct nl_addr *l_bcast;
172	char		l_qdisc[IFQDISCSIZ];
173	struct rtnl_link_map l_map;
174	uint64_t	l_stats[RTNL_LINK_STATS_MAX+1];
175	uint32_t	l_flag_mask;
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
241#define NEXTHOP_HAS_FLAGS   0x000001
242#define NEXTHOP_HAS_WEIGHT  0x000002
243#define NEXTHOP_HAS_IFINDEX 0x000004
244#define NEXTHOP_HAS_GATEWAY 0x000008
245
246struct rtnl_nexthop
247{
248	uint8_t			rtnh_flags;
249	uint8_t			rtnh_flag_mask;
250	uint8_t			rtnh_weight;
251	/* 1 byte spare */
252	uint32_t		rtnh_ifindex;
253	struct nl_addr *	rtnh_gateway;
254	uint32_t		rtnh_mask;
255
256	struct nl_list_head	rtnh_list;
257};
258
259struct rtnl_route
260{
261	NLHDR_COMMON
262
263	uint8_t			rt_family;
264	uint8_t			rt_dst_len;
265	uint8_t			rt_src_len;
266	uint8_t			rt_tos;
267	uint8_t			rt_table;
268	uint8_t			rt_protocol;
269	uint8_t			rt_scope;
270	uint8_t			rt_type;
271	uint32_t		rt_flags;
272	struct nl_addr *	rt_dst;
273	struct nl_addr *	rt_src;
274	char			rt_iif[IFNAMSIZ];
275	uint32_t		rt_oif;
276	struct nl_addr *	rt_gateway;
277	uint32_t		rt_prio;
278	uint32_t		rt_metrics[RTAX_MAX];
279	uint32_t		rt_metrics_mask;
280	struct nl_addr *	rt_pref_src;
281	struct nl_list_head	rt_nexthops;
282	realm_t			rt_realms;
283	struct rtnl_rtcacheinfo	rt_cacheinfo;
284	uint32_t		rt_mp_algo;
285	uint32_t		rt_flag_mask;
286};
287
288struct rtnl_rule
289{
290	NLHDR_COMMON
291
292	uint64_t	r_mark;
293	uint32_t	r_prio;
294	uint32_t	r_realms;
295	uint32_t	r_table;
296	uint8_t		r_dsfield;
297	uint8_t		r_type;
298	uint8_t		r_family;
299	uint8_t		r_src_len;
300	uint8_t		r_dst_len;
301	char		r_iif[IFNAMSIZ];
302	struct nl_addr *r_src;
303	struct nl_addr *r_dst;
304	struct nl_addr *r_srcmap;
305};
306
307struct rtnl_neightbl_parms
308{
309	/**
310	 * Interface index of the device this parameter set is assigned
311	 * to or 0 for the default set.
312	 */
313	uint32_t		ntp_ifindex;
314
315	/**
316	 * Number of references to this parameter set.
317	 */
318	uint32_t		ntp_refcnt;
319
320	/**
321	 * Queue length for pending arp requests, i.e. the number of
322	 * packets which are accepted from other layers while the
323	 * neighbour address is still being resolved
324	 */
325	uint32_t		ntp_queue_len;
326
327	/**
328	 * Number of requests to send to the user level ARP daemon.
329	 * Specify 0 to disable.
330	 */
331	uint32_t		ntp_app_probes;
332
333	/**
334	 * Maximum number of retries for unicast solicitation.
335	 */
336	uint32_t		ntp_ucast_probes;
337
338	/**
339	 * Maximum number of retries for multicast solicitation.
340	 */
341	uint32_t		ntp_mcast_probes;
342
343	/**
344	 * Base value in milliseconds to ompute reachable time, see RFC2461.
345	 */
346	uint64_t		ntp_base_reachable_time;
347
348	/**
349	 * Actual reachable time (read-only)
350	 */
351	uint64_t		ntp_reachable_time;	/* secs */
352
353	/**
354	 * The time in milliseconds between retransmitted Neighbor
355	 * Solicitation messages.
356	 */
357	uint64_t		ntp_retrans_time;
358
359	/**
360	 * Interval in milliseconds to check for stale neighbour
361	 * entries.
362	 */
363	uint64_t		ntp_gc_stale_time;	/* secs */
364
365	/**
366	 * Delay in milliseconds for the first time probe if
367	 * the neighbour is reachable.
368	 */
369	uint64_t		ntp_probe_delay;	/* secs */
370
371	/**
372	 * Maximum delay in milliseconds of an answer to a neighbour
373	 * solicitation message.
374	 */
375	uint64_t		ntp_anycast_delay;
376
377	/**
378	 * Minimum age in milliseconds before a neighbour entry
379	 * may be replaced.
380	 */
381	uint64_t		ntp_locktime;
382
383	/**
384	 * Delay in milliseconds before answering to an ARP request
385	 * for which a proxy ARP entry exists.
386	 */
387	uint64_t		ntp_proxy_delay;
388
389	/**
390	 * Queue length for the delayed proxy arp requests.
391	 */
392	uint32_t		ntp_proxy_qlen;
393
394	/**
395	 * Mask of available parameter attributes
396	 */
397	uint32_t		ntp_mask;
398};
399
400#define NTBLNAMSIZ	32
401
402/**
403 * Neighbour table
404 * @ingroup neightbl
405 */
406struct rtnl_neightbl
407{
408	NLHDR_COMMON
409
410	char			nt_name[NTBLNAMSIZ];
411	uint32_t		nt_family;
412	uint32_t		nt_gc_thresh1;
413	uint32_t		nt_gc_thresh2;
414	uint32_t		nt_gc_thresh3;
415	uint64_t		nt_gc_interval;
416	struct ndt_config	nt_config;
417	struct rtnl_neightbl_parms nt_parms;
418	struct ndt_stats	nt_stats;
419};
420
421struct rtnl_ratespec
422{
423	uint8_t			rs_cell_log;
424	uint16_t		rs_feature;
425	uint16_t		rs_addend;
426	uint16_t		rs_mpu;
427	uint32_t		rs_rate;
428};
429
430struct rtnl_tstats
431{
432	struct {
433		uint64_t            bytes;
434		uint64_t            packets;
435	} tcs_basic;
436
437	struct {
438		uint32_t            bps;
439		uint32_t            pps;
440	} tcs_rate_est;
441
442	struct {
443		uint32_t            qlen;
444		uint32_t            backlog;
445		uint32_t            drops;
446		uint32_t            requeues;
447		uint32_t            overlimits;
448	} tcs_queue;
449};
450
451#define TCKINDSIZ	32
452
453#define NL_TCA_GENERIC(pre)				\
454	NLHDR_COMMON					\
455	uint32_t		pre ##_family;		\
456	uint32_t		pre ##_ifindex;		\
457	uint32_t		pre ##_handle;		\
458	uint32_t		pre ##_parent;		\
459	uint32_t		pre ##_info;		\
460	char			pre ##_kind[TCKINDSIZ];	\
461	struct nl_data *	pre ##_opts;		\
462	uint64_t		pre ##_stats[RTNL_TC_STATS_MAX+1]; \
463	struct nl_data *	pre ##_xstats;		\
464	void *			pre ##_subdata;		\
465
466
467struct rtnl_tca
468{
469	NL_TCA_GENERIC(tc);
470};
471
472struct rtnl_qdisc
473{
474	NL_TCA_GENERIC(q);
475	struct rtnl_qdisc_ops	*q_ops;
476};
477
478struct rtnl_class
479{
480	NL_TCA_GENERIC(c);
481	struct rtnl_class_ops	*c_ops;
482};
483
484struct rtnl_cls
485{
486	NL_TCA_GENERIC(c);
487	uint32_t	c_prio;
488	uint32_t	c_protocol;
489	struct rtnl_cls_ops	*c_ops;
490};
491
492struct rtnl_u32
493{
494	uint32_t		cu_divisor;
495	uint32_t		cu_hash;
496	uint32_t		cu_classid;
497	uint32_t		cu_link;
498	struct nl_data *	cu_pcnt;
499	struct nl_data *	cu_selector;
500	struct nl_data *	cu_act;
501	struct nl_data *	cu_police;
502	char			cu_indev[IFNAMSIZ];
503	int			cu_mask;
504};
505
506struct rtnl_fw
507{
508	uint32_t		cf_classid;
509	struct nl_data *	cf_act;
510	struct nl_data *	cf_police;
511	char			cf_indev[IFNAMSIZ];
512	int			cf_mask;
513};
514
515struct rtnl_dsmark_qdisc
516{
517	uint16_t	qdm_indices;
518	uint16_t	qdm_default_index;
519	uint32_t	qdm_set_tc_index;
520	uint32_t	qdm_mask;
521};
522
523struct rtnl_dsmark_class
524{
525	uint8_t		cdm_bmask;
526	uint8_t		cdm_value;
527	uint32_t	cdm_mask;
528};
529
530struct rtnl_fifo
531{
532	uint32_t	qf_limit;
533	uint32_t	qf_mask;
534};
535
536struct rtnl_prio
537{
538	uint32_t	qp_bands;
539	uint8_t		qp_priomap[TC_PRIO_MAX+1];
540	uint32_t	qp_mask;
541};
542
543struct rtnl_tbf
544{
545	uint32_t		qt_limit;
546	uint32_t		qt_mpu;
547	struct rtnl_ratespec	qt_rate;
548	uint32_t		qt_rate_bucket;
549	uint32_t		qt_rate_txtime;
550	struct rtnl_ratespec	qt_peakrate;
551	uint32_t		qt_peakrate_bucket;
552	uint32_t		qt_peakrate_txtime;
553	uint32_t		qt_mask;
554};
555
556struct rtnl_sfq
557{
558	uint32_t	qs_quantum;
559	uint32_t	qs_perturb;
560	uint32_t	qs_limit;
561	uint32_t	qs_divisor;
562	uint32_t	qs_flows;
563	uint32_t	qs_mask;
564};
565
566struct rtnl_netem_corr
567{
568	uint32_t	nmc_delay;
569	uint32_t	nmc_loss;
570	uint32_t	nmc_duplicate;
571};
572
573struct rtnl_netem_reo
574{
575	uint32_t	nmro_probability;
576	uint32_t	nmro_correlation;
577};
578
579struct rtnl_netem
580{
581	uint32_t		qnm_latency;
582	uint32_t		qnm_limit;
583	uint32_t		qnm_loss;
584	uint32_t		qnm_gap;
585	uint32_t		qnm_duplicate;
586	uint32_t		qnm_jitter;
587	uint32_t		qnm_mask;
588	struct rtnl_netem_corr	qnm_corr;
589	struct rtnl_netem_reo	qnm_ro;
590};
591
592struct rtnl_htb_qdisc
593{
594	uint32_t		qh_rate2quantum;
595	uint32_t		qh_defcls;
596	uint32_t		qh_mask;
597};
598
599struct rtnl_htb_class
600{
601	uint32_t		ch_prio;
602	uint32_t		ch_mtu;
603	struct rtnl_ratespec	ch_rate;
604	struct rtnl_ratespec	ch_ceil;
605	uint32_t		ch_rbuffer;
606	uint32_t		ch_cbuffer;
607	uint32_t		ch_quantum;
608	uint8_t			ch_overhead;
609	uint8_t			ch_mpu;
610	uint32_t		ch_mask;
611};
612
613struct rtnl_cbq
614{
615	struct tc_cbq_lssopt    cbq_lss;
616	struct tc_ratespec      cbq_rate;
617	struct tc_cbq_wrropt    cbq_wrr;
618	struct tc_cbq_ovl       cbq_ovl;
619	struct tc_cbq_fopt      cbq_fopt;
620	struct tc_cbq_police    cbq_police;
621};
622
623struct rtnl_red
624{
625	uint32_t	qr_limit;
626	uint32_t	qr_qth_min;
627	uint32_t	qr_qth_max;
628	uint8_t		qr_flags;
629	uint8_t		qr_wlog;
630	uint8_t		qr_plog;
631	uint8_t		qr_scell_log;
632	uint32_t	qr_mask;
633};
634
635struct flnl_request
636{
637	NLHDR_COMMON
638
639	struct nl_addr *	lr_addr;
640	uint32_t		lr_fwmark;
641	uint8_t			lr_tos;
642	uint8_t			lr_scope;
643	uint8_t			lr_table;
644};
645
646
647struct flnl_result
648{
649	NLHDR_COMMON
650
651	struct flnl_request *	fr_req;
652	uint8_t			fr_table_id;
653	uint8_t			fr_prefixlen;
654	uint8_t			fr_nh_sel;
655	uint8_t			fr_type;
656	uint8_t			fr_scope;
657	uint32_t		fr_error;
658};
659
660#define GENL_OP_HAS_POLICY	1
661#define GENL_OP_HAS_DOIT	2
662#define GENL_OP_HAS_DUMPIT	4
663
664struct genl_family_op
665{
666	uint32_t		o_id;
667	uint32_t		o_flags;
668
669	struct nl_list_head	o_list;
670};
671
672struct genl_family
673{
674	NLHDR_COMMON
675
676	uint16_t		gf_id;
677	char 			gf_name[GENL_NAMSIZ];
678	uint32_t		gf_version;
679	uint32_t		gf_hdrsize;
680	uint32_t		gf_maxattr;
681
682	struct nl_list_head	gf_ops;
683};
684
685union nfnl_ct_proto
686{
687	struct {
688		uint16_t	src;
689		uint16_t	dst;
690	} port;
691	struct {
692		uint16_t	id;
693		uint8_t		type;
694		uint8_t		code;
695	} icmp;
696};
697
698struct nfnl_ct_dir {
699	struct nl_addr *	src;
700	struct nl_addr *	dst;
701	union nfnl_ct_proto	proto;
702	uint64_t		packets;
703	uint64_t		bytes;
704};
705
706union nfnl_ct_protoinfo {
707	struct {
708		uint8_t		state;
709	} tcp;
710};
711
712struct nfnl_ct {
713	NLHDR_COMMON
714
715	uint8_t			ct_family;
716	uint8_t			ct_proto;
717	union nfnl_ct_protoinfo	ct_protoinfo;
718
719	uint32_t		ct_status;
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	uint8_t			log_family;
733	uint8_t			log_hook;
734	uint16_t		log_hwproto;
735	uint32_t		log_mark;
736	struct timeval		log_timestamp;
737	uint32_t		log_indev;
738	uint32_t		log_outdev;
739	uint32_t		log_physindev;
740	uint32_t		log_physoutdev;
741	uint8_t			log_hwaddr[8];
742	int			log_hwaddr_len;
743	void *			log_payload;
744	int			log_payload_len;
745	char *			log_prefix;
746	uint32_t		log_uid;
747	uint32_t		log_seq;
748	uint32_t		log_seq_global;
749};
750
751#endif
752