oops
[libnl.git] / include / netlink-types.h
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
20 struct nl_cache_ops;
21
22 #define NL_SOCK_BUFSIZE_SET 1
23 #define NL_SOCK_PASSCRED 2
24
25 #define NL_MSG_CRED_PRESENT 1
26
27 struct nl_handle;
28 struct nl_object;
29
30 struct nl_cb
31 {
32         nl_recvmsg_msg_cb_t     cb_set[NL_CB_TYPE_MAX+1];
33         void *                  cb_args[NL_CB_TYPE_MAX+1];
34         
35         nl_recvmsg_err_cb_t     cb_err;
36         void *                  cb_err_arg;
37
38         /** May be used to replace nl_recvmsgs with your own implementation
39          * in all internal calls to nl_recvmsgs. */
40         int                     (*cb_recvmsgs_ow)(struct nl_handle *,
41                                                   struct nl_cb *);
42
43         /** Overwrite internal calls to nl_recv, must return the number of
44          * octets read and allocate a buffer for the received data. */
45         int                     (*cb_recv_ow)(struct nl_handle *,
46                                               struct sockaddr_nl *,
47                                               unsigned char **,
48                                               struct ucred **);
49
50         /** Overwrites internal calls to nl_send, must send the netlink
51          * message. */
52         int                     (*cb_send_ow)(struct nl_handle *,
53                                               struct nl_msg *);
54 };
55
56 struct nl_handle
57 {
58         struct sockaddr_nl      h_local;
59         struct sockaddr_nl      h_peer;
60         int                     h_fd;
61         int                     h_proto;
62         unsigned int            h_seq_next;
63         unsigned int            h_seq_expect;
64         int                     h_flags;
65         struct nl_cb *          h_cb;
66 };
67
68 struct nl_cache
69 {
70         struct nl_list_head     c_items;
71         int                     c_nitems;
72         int                     c_iarg1;
73         int                     c_iarg2;
74         struct nl_cache_ops *   c_ops;
75 };
76
77 struct nl_parser_param;
78
79 struct nl_msgtype
80 {
81         int                     mt_id;
82         char *                  mt_name;
83 };
84
85 struct nl_cache_ops
86 {
87         char  *                 co_name;
88         size_t                  co_size;
89         int                     co_hdrsize;
90         int                     co_protocol;
91         
92         /**
93          * Called whenever an update of the cache is required. Must send
94          * a request message to the kernel requesting a complete dump.
95          */
96         int   (*co_request_update)(struct nl_cache *, struct nl_handle *);
97
98         /**
99          * Called whenever a new object was allocated
100          */
101         void  (*co_constructor)(struct nl_object *);
102
103         /**
104          * Called whenever a object in the cache gets destroyed, must
105          * free the type specific memory allocations
106          */
107         void  (*co_free_data)(struct nl_object *);
108
109         /**
110          * Called whenever a message was received that needs to be parsed.
111          * Must parse the message and call the paser callback function
112          * (nl_parser_param) provided via the argument.
113          */
114         int   (*co_msg_parser)(struct sockaddr_nl *, struct nlmsghdr *, void *);
115
116         /**
117          * Called whenever a dump of a cache object is requested. Must
118          * dump the specified object to the specified file descriptor
119          */
120         int   (*co_dump[NL_DUMP_MAX+1])(struct nl_object *,
121                                         struct nl_dump_params *);
122
123         /**
124          * Must compare the two specified objects and return a non-zero
125          * value if they match.
126          */
127         int   (*co_filter)(struct nl_object *, struct nl_object *);
128
129
130         struct nl_cache_ops *co_next;
131         struct nl_cache *co_major_cache;
132         struct nl_msgtype       co_msgtypes[];
133 };
134
135 #define NLHDR_COMMON                            \
136         int                     ce_refcnt;      \
137         struct nl_cache_ops *   ce_ops;         \
138         struct nl_cache *       ce_cache;       \
139         struct nl_object *      ce_dataref;     \
140         struct nl_list_head     ce_list;        \
141         int                     ce_msgtype;
142
143 struct nl_object
144 {
145         NLHDR_COMMON
146 };
147
148 struct nl_parser_param
149 {
150         int             (*pp_cb)(struct nl_object *, struct nl_parser_param *);
151         void *            pp_arg;
152 };
153
154 struct nl_data
155 {
156         size_t                  d_size;
157         void *                  d_data;
158 };
159
160 struct nl_addr
161 {
162         int                     a_family;
163         unsigned int            a_maxsize;
164         unsigned int            a_len;
165         int                     a_prefixlen;
166         int                     a_refcnt;
167         unsigned char           a_addr[0];
168 };
169
170 struct nl_msg
171 {
172         int                     nm_protocol;
173         int                     nm_flags;
174         struct sockaddr_nl      nm_src;
175         struct sockaddr_nl      nm_dst;
176         struct ucred            nm_creds;
177         struct nlmsghdr *       nm_nlh;
178 };
179
180 struct rtnl_link_map
181 {
182         uint64_t lm_mem_start;
183         uint64_t lm_mem_end;
184         uint64_t lm_base_addr;
185         uint16_t lm_irq;
186         uint8_t  lm_dma;
187         uint8_t  lm_port;
188 };
189
190 #define IFQDISCSIZ      32
191
192 struct rtnl_link
193 {
194         NLHDR_COMMON
195
196         char            l_name[IFNAMSIZ];
197
198         uint32_t        l_family;
199         uint32_t        l_arptype;
200         uint32_t        l_index;
201         uint32_t        l_flags;
202         uint32_t        l_change;
203         uint32_t        l_mtu;
204         uint32_t        l_link;
205         uint32_t        l_txqlen;
206         uint32_t        l_weight;
207         uint32_t        l_master;
208         struct nl_addr *l_addr; 
209         struct nl_addr *l_bcast;
210         char            l_qdisc[IFQDISCSIZ];
211         struct rtnl_link_map l_map;
212         uint64_t        l_stats[RTNL_LINK_STATS_MAX+1];
213         uint32_t        l_mask; 
214         uint32_t        l_flag_mask;
215 };
216
217 struct rtnl_ncacheinfo
218 {
219         uint32_t nci_confirmed; /**< Time since neighbour validty was last confirmed */
220         uint32_t nci_used;      /**< Time since neighbour entry was last ued */
221         uint32_t nci_updated;   /**< Time since last update */
222         uint32_t nci_refcnt;    /**< Reference counter */
223 };
224
225
226 struct rtnl_neigh
227 {
228         NLHDR_COMMON
229         uint32_t        n_family;
230         uint32_t        n_ifindex;
231         uint16_t        n_state;
232         uint8_t         n_flags;
233         uint8_t         n_type; 
234         struct nl_addr *n_lladdr;
235         struct nl_addr *n_dst;  
236         uint32_t        n_probes;
237         struct rtnl_ncacheinfo n_cacheinfo;
238         uint32_t                n_mask;
239         uint32_t                n_state_mask;
240         uint32_t                n_flag_mask;
241 };
242
243
244 struct rtnl_addr_cacheinfo
245 {
246         /* Preferred lifetime in seconds */
247         uint32_t aci_prefered;
248
249         /* Valid lifetime in seconds */
250         uint32_t aci_valid;
251
252         /* Timestamp of creation in 1/100s seince boottime */
253         uint32_t aci_cstamp;
254
255         /* Timestamp of last update in 1/100s since boottime */
256         uint32_t aci_tstamp;
257 };
258
259 struct rtnl_addr
260 {
261         NLHDR_COMMON
262
263         uint8_t         a_family;
264         uint8_t         a_prefixlen;
265         uint8_t         a_flags;
266         uint8_t         a_scope;
267         uint32_t        a_ifindex;
268
269         struct nl_addr *a_peer; 
270         struct nl_addr *a_local;
271         struct nl_addr *a_bcast;
272         struct nl_addr *a_anycast;
273         struct nl_addr *a_multicast;
274
275         struct rtnl_addr_cacheinfo a_cacheinfo;
276         
277         char a_label[IFNAMSIZ];
278         uint32_t a_mask;
279         uint32_t a_flag_mask;
280 };
281
282 struct rtnl_nexthop
283 {
284         uint8_t                 rtnh_flags;
285         uint8_t                 rtnh_flag_mask;
286         uint8_t                 rtnh_weight;
287         /* 1 byte spare */
288         uint32_t                rtnh_ifindex;
289         struct nl_addr *        rtnh_gateway;
290         uint32_t                rtnh_mask;
291
292         struct nl_list_head     rtnh_list;
293 };
294
295 struct rtnl_rtcacheinfo
296 {
297         uint32_t        rtci_clntref;
298         uint32_t        rtci_last_use;
299         uint32_t        rtci_expires;
300         int32_t         rtci_error;
301         uint32_t        rtci_used;
302         uint32_t        rtci_id;
303         uint32_t        rtci_ts;
304         uint32_t        rtci_tsage;
305 };
306
307 struct rtnl_route
308 {
309         NLHDR_COMMON
310
311         uint8_t                 rt_family;
312         uint8_t                 rt_dst_len;
313         uint8_t                 rt_src_len;
314         uint8_t                 rt_tos;
315         uint8_t                 rt_table;
316         uint8_t                 rt_protocol;
317         uint8_t                 rt_scope;
318         uint8_t                 rt_type;
319         uint32_t                rt_flags;
320         struct nl_addr *        rt_dst;
321         struct nl_addr *        rt_src;
322         char                    rt_iif[IFNAMSIZ];
323         uint32_t                rt_oif;
324         struct nl_addr *        rt_gateway;
325         uint32_t                rt_prio;
326         uint32_t                rt_metrics[RTAX_MAX];
327         uint32_t                rt_metrics_mask;
328         struct nl_addr *        rt_pref_src;
329         struct nl_list_head     rt_nexthops;
330         realm_t                 rt_realms;
331         struct rtnl_rtcacheinfo rt_cacheinfo;
332         uint32_t                rt_mp_algo;
333         uint32_t                rt_flag_mask;
334         uint32_t                rt_mask;
335 };
336
337 struct rtnl_rule
338 {
339         NLHDR_COMMON
340
341         uint64_t        r_fwmark;
342         uint32_t        r_prio;
343         uint32_t        r_realms;
344         uint32_t        r_table;
345         uint8_t         r_dsfield;
346         uint8_t         r_type;
347         uint8_t         r_family;
348         uint8_t         r_src_len;
349         uint8_t         r_dst_len;
350         char            r_iif[IFNAMSIZ];
351         struct nl_addr *r_src;
352         struct nl_addr *r_dst;
353         struct nl_addr *r_srcmap;
354
355         uint32_t        r_mask; 
356 };
357
358 struct rtnl_neightbl_parms
359 {
360         /**
361          * Interface index of the device this parameter set is assigned
362          * to or 0 for the default set.
363          */
364         uint32_t                ntp_ifindex;
365
366         /**
367          * Number of references to this parameter set.
368          */
369         uint32_t                ntp_refcnt;
370
371         /**
372          * Queue length for pending arp requests, i.e. the number of
373          * packets which are accepted from other layers while the
374          * neighbour address is still being resolved
375          */
376         uint32_t                ntp_queue_len;
377
378         /**
379          * Number of requests to send to the user level ARP daemon.
380          * Specify 0 to disable.
381          */
382         uint32_t                ntp_app_probes;
383
384         /**
385          * Maximum number of retries for unicast solicitation.
386          */
387         uint32_t                ntp_ucast_probes;
388
389         /**
390          * Maximum number of retries for multicast solicitation.
391          */
392         uint32_t                ntp_mcast_probes;
393
394         /**
395          * Base value in milliseconds to ompute reachable time, see RFC2461.
396          */
397         uint64_t                ntp_base_reachable_time;
398
399         /**
400          * Actual reachable time (read-only)
401          */
402         uint64_t                ntp_reachable_time;     /* secs */
403
404         /**
405          * The time in milliseconds between retransmitted Neighbor
406          * Solicitation messages.
407          */
408         uint64_t                ntp_retrans_time;
409
410         /**
411          * Interval in milliseconds to check for stale neighbour
412          * entries.
413          */
414         uint64_t                ntp_gc_stale_time;      /* secs */
415
416         /**
417          * Delay in milliseconds for the first time probe if
418          * the neighbour is reachable.
419          */
420         uint64_t                ntp_probe_delay;        /* secs */
421
422         /**
423          * Maximum delay in milliseconds of an answer to a neighbour
424          * solicitation message.
425          */
426         uint64_t                ntp_anycast_delay;
427
428         /**
429          * Minimum age in milliseconds before a neighbour entry
430          * may be replaced.
431          */
432         uint64_t                ntp_locktime;
433
434         /**
435          * Delay in milliseconds before answering to an ARP request
436          * for which a proxy ARP entry exists.
437          */
438         uint64_t                ntp_proxy_delay;
439
440         /**
441          * Queue length for the delayed proxy arp requests.
442          */
443         uint32_t                ntp_proxy_qlen;
444         
445         /**
446          * Mask of available parameter attributes
447          */
448         uint32_t                ntp_mask;
449 };
450
451 #define NTBLNAMSIZ      32
452
453 /**
454  * Neighbour table
455  * @ingroup neightbl
456  */
457 struct rtnl_neightbl
458 {
459         NLHDR_COMMON
460
461         char                    nt_name[NTBLNAMSIZ];
462         uint32_t                nt_family;
463         uint32_t                nt_gc_thresh1;
464         uint32_t                nt_gc_thresh2;
465         uint32_t                nt_gc_thresh3;
466         uint64_t                nt_gc_interval;
467         struct ndt_config       nt_config;
468         struct rtnl_neightbl_parms nt_parms;
469         struct ndt_stats        nt_stats;
470         uint32_t                nt_mask;
471 };
472
473 struct rtnl_ratespec
474 {
475         uint8_t                 rs_cell_log;
476         uint16_t                rs_feature;
477         uint16_t                rs_addend;
478         uint16_t                rs_mpu;
479         uint32_t                rs_rate;
480 };
481
482 struct rtnl_tstats
483 {
484         struct {
485                 uint64_t            bytes;
486                 uint64_t            packets;
487         } tcs_basic;
488
489         struct {
490                 uint32_t            bps;
491                 uint32_t            pps;
492         } tcs_rate_est;
493
494         struct {
495                 uint32_t            qlen;
496                 uint32_t            backlog;
497                 uint32_t            drops;
498                 uint32_t            requeues;
499                 uint32_t            overlimits;
500         } tcs_queue;
501 };
502
503 #define TCKINDSIZ       32
504
505 #define NL_TCA_GENERIC(pre)                             \
506         NLHDR_COMMON                                    \
507         uint32_t                pre ##_family;          \
508         uint32_t                pre ##_ifindex;         \
509         uint32_t                pre ##_handle;          \
510         uint32_t                pre ##_parent;          \
511         uint32_t                pre ##_info;            \
512         char                    pre ##_kind[TCKINDSIZ]; \
513         struct nl_data *        pre ##_opts;            \
514         uint64_t                pre ##_stats[RTNL_TC_STATS_MAX+1]; \
515         struct nl_data *        pre ##_xstats;          \
516         void *                  pre ##_subdata;         \
517         int                     pre ##_mask
518
519
520 struct rtnl_tca
521 {
522         NL_TCA_GENERIC(tc);
523 };
524
525 struct rtnl_qdisc
526 {
527         NL_TCA_GENERIC(q);
528         struct rtnl_qdisc_ops   *q_ops;
529 };
530
531 struct rtnl_class
532 {
533         NL_TCA_GENERIC(c);
534         struct rtnl_class_ops   *c_ops;
535 };
536
537 struct rtnl_cls
538 {
539         NL_TCA_GENERIC(c);
540         uint32_t        c_prio;
541         uint32_t        c_protocol;
542         struct rtnl_cls_ops     *c_ops;
543 };
544
545 struct rtnl_u32
546 {
547         uint32_t                cu_divisor;
548         uint32_t                cu_hash;
549         uint32_t                cu_classid;
550         uint32_t                cu_link;
551         struct nl_data *        cu_pcnt;
552         struct nl_data *        cu_selector;
553         struct nl_data *        cu_act;
554         struct nl_data *        cu_police;
555         char                    cu_indev[IFNAMSIZ];
556         int                     cu_mask;
557 };
558
559 struct rtnl_fw
560 {
561         uint32_t                cf_classid;
562         struct nl_data *        cf_act;
563         struct nl_data *        cf_police;
564         char                    cf_indev[IFNAMSIZ];
565         int                     cf_mask;
566 };
567
568 struct rtnl_dsmark_qdisc
569 {
570         uint16_t        qdm_indices;
571         uint16_t        qdm_default_index;
572         uint32_t        qdm_set_tc_index;
573         uint32_t        qdm_mask;
574 };
575
576 struct rtnl_dsmark_class
577 {
578         uint8_t         cdm_bmask;
579         uint8_t         cdm_value;
580         uint32_t        cdm_mask;
581 };
582
583 struct rtnl_fifo
584 {
585         uint32_t        qf_limit;
586         uint32_t        qf_mask;
587 };
588
589 struct rtnl_prio
590 {
591         uint32_t        qp_bands;
592         uint8_t         qp_priomap[TC_PRIO_MAX+1];
593         uint32_t        qp_mask;
594 };
595
596 struct rtnl_tbf
597 {
598         uint32_t                qt_limit;
599         uint32_t                qt_mpu;
600         struct rtnl_ratespec    qt_rate;
601         uint32_t                qt_rate_bucket;
602         uint32_t                qt_rate_txtime;
603         struct rtnl_ratespec    qt_peakrate;
604         uint32_t                qt_peakrate_bucket;
605         uint32_t                qt_peakrate_txtime;
606         uint32_t                qt_mask;
607 };
608
609 struct rtnl_sfq
610 {
611         uint32_t        qs_quantum;
612         uint32_t        qs_perturb;
613         uint32_t        qs_limit;
614         uint32_t        qs_divisor;
615         uint32_t        qs_flows;
616         uint32_t        qs_mask;
617 };
618
619 struct rtnl_netem_corr
620 {
621         uint32_t        nmc_delay;
622         uint32_t        nmc_loss;
623         uint32_t        nmc_duplicate;
624 };
625
626 struct rtnl_netem_reo
627 {
628         uint32_t        nmro_probability;
629         uint32_t        nmro_correlation;
630 };
631
632 struct rtnl_netem
633 {
634         uint32_t                qnm_latency;
635         uint32_t                qnm_limit;
636         uint32_t                qnm_loss;
637         uint32_t                qnm_gap;
638         uint32_t                qnm_duplicate;
639         uint32_t                qnm_jitter;
640         uint32_t                qnm_mask;
641         struct rtnl_netem_corr  qnm_corr;
642         struct rtnl_netem_reo   qnm_ro;
643 };
644
645 struct rtnl_htb_qdisc
646 {
647         uint32_t                qh_rate2quantum;
648         uint32_t                qh_defcls;
649         uint32_t                qh_mask;
650 };
651
652 struct rtnl_htb_class
653 {
654         uint32_t                ch_prio;
655         uint32_t                ch_mtu;
656         struct rtnl_ratespec    ch_rate;
657         struct rtnl_ratespec    ch_ceil;
658         uint32_t                ch_rbuffer;
659         uint32_t                ch_cbuffer;
660         uint32_t                ch_mask;
661 };
662
663 struct rtnl_cbq
664 {
665         struct tc_cbq_lssopt    cbq_lss;
666         struct tc_ratespec      cbq_rate;
667         struct tc_cbq_wrropt    cbq_wrr;
668         struct tc_cbq_ovl       cbq_ovl;
669         struct tc_cbq_fopt      cbq_fopt;
670         struct tc_cbq_police    cbq_police;
671 };
672
673 struct rtnl_red
674 {
675         uint32_t        qr_limit;
676         uint32_t        qr_qth_min;
677         uint32_t        qr_qth_max;
678         uint8_t         qr_flags;
679         uint8_t         qr_wlog;
680         uint8_t         qr_plog;
681         uint8_t         qr_scell_log;
682         uint32_t        qr_mask;
683 };
684
685 struct flnl_request
686 {
687         struct nl_addr *        lr_addr;
688         uint32_t                lr_fwmark;
689         uint8_t                 lr_tos;
690         uint8_t                 lr_scope;
691         uint8_t                 lr_table;
692         uint32_t                lr_mask;
693         int                     lr_refcnt;
694 };
695
696
697 struct flnl_result
698 {
699         NLHDR_COMMON
700
701         struct flnl_request *   fr_req;
702         uint8_t                 fr_table_id;
703         uint8_t                 fr_prefixlen;
704         uint8_t                 fr_nh_sel;
705         uint8_t                 fr_type;
706         uint8_t                 fr_scope;
707         uint32_t                fr_error;
708 };
709
710 #endif