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