kernel.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /*
  2. Copyright (c) 2007, 2008 by Juliusz Chroboczek
  3. Permission is hereby granted, free of charge, to any person obtaining a copy
  4. of this software and associated documentation files (the "Software"), to deal
  5. in the Software without restriction, including without limitation the rights
  6. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  7. copies of the Software, and to permit persons to whom the Software is
  8. furnished to do so, subject to the following conditions:
  9. The above copyright notice and this permission notice shall be included in
  10. all copies or substantial portions of the Software.
  11. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  12. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  13. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  14. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  15. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  16. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  17. THE SOFTWARE.
  18. */
  19. #include <netinet/in.h>
  20. #include "babeld.h"
  21. #define KERNEL_INFINITY 0xFFFF
  22. struct kernel_route {
  23. unsigned char prefix[16];
  24. int plen;
  25. unsigned char src_prefix[16];
  26. int src_plen; /* no source prefix <=> src_plen == 0 */
  27. int metric;
  28. unsigned int ifindex;
  29. int proto;
  30. unsigned char gw[16];
  31. };
  32. struct kernel_addr {
  33. struct in6_addr addr;
  34. unsigned int ifindex;
  35. };
  36. struct kernel_link {
  37. char *ifname;
  38. };
  39. struct kernel_rule {
  40. unsigned int priority;
  41. unsigned int table;
  42. unsigned char src[16];
  43. unsigned char src_plen;
  44. };
  45. struct kernel_filter {
  46. /* return -1 to interrupt search. */
  47. int (*addr)(struct kernel_addr *, void *);
  48. void *addr_closure;
  49. int (*route)(struct kernel_route *, void *);
  50. void *route_closure;
  51. int (*link)(struct kernel_link *, void *);
  52. void *link_closure;
  53. int (*rule)(struct kernel_rule *, void *);
  54. void *rule_closure;
  55. };
  56. #define ROUTE_FLUSH 0
  57. #define ROUTE_ADD 1
  58. #define ROUTE_MODIFY 2
  59. #define CHANGE_LINK (1 << 0)
  60. #define CHANGE_ROUTE (1 << 1)
  61. #define CHANGE_ADDR (1 << 2)
  62. #define CHANGE_RULE (1 << 3)
  63. #ifndef MAX_IMPORT_TABLES
  64. #define MAX_IMPORT_TABLES 10
  65. #endif
  66. extern int export_table, import_tables[MAX_IMPORT_TABLES], import_table_count;
  67. int add_import_table(int table);
  68. int kernel_setup(int setup);
  69. int kernel_setup_socket(int setup);
  70. int kernel_setup_interface(int setup, const char *ifname, int ifindex);
  71. int kernel_interface_operational(const char *ifname, int ifindex);
  72. int kernel_interface_ipv4(const char *ifname, int ifindex,
  73. unsigned char *addr_r);
  74. int kernel_interface_mtu(const char *ifname, int ifindex);
  75. int kernel_interface_wireless(const char *ifname, int ifindex);
  76. int kernel_interface_channel(const char *ifname, int ifindex);
  77. int kernel_disambiguate(int v4);
  78. int kernel_route(int operation, int table,
  79. const unsigned char *dest, unsigned short plen,
  80. const unsigned char *src, unsigned short src_plen,
  81. const unsigned char *gate, int ifindex, unsigned int metric,
  82. const unsigned char *newgate, int newifindex,
  83. unsigned int newmetric, int newtable);
  84. int kernel_dump(int operation, struct kernel_filter *filter);
  85. int kernel_callback(struct kernel_filter *filter);
  86. int if_eui64(char *ifname, int ifindex, unsigned char *eui);
  87. int gettime(struct timeval *tv);
  88. int read_random_bytes(void *buf, int len);
  89. int kernel_older_than(const char *sysname, int version, int sub_version);
  90. int kernel_has_ipv6_subtrees(void);
  91. int add_rule(int prio, const unsigned char *src_prefix, int src_plen,
  92. int table);
  93. int flush_rule(int prio, int family);
  94. int change_rule(int new_prio, int old_prio, const unsigned char *src, int plen,
  95. int table);