2
0

interface-ip.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. /*
  2. * netifd - network interface daemon
  3. * Copyright (C) 2012 Felix Fietkau <nbd@openwrt.org>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License version 2
  7. * as published by the Free Software Foundation
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. */
  14. #ifndef __INTERFACE_IP_H
  15. #define __INTERFACE_IP_H
  16. #include "interface.h"
  17. enum device_addr_flags {
  18. /* address family for routes and addresses */
  19. DEVADDR_INET4 = (0 << 0),
  20. DEVADDR_INET6 = (1 << 0),
  21. DEVADDR_FAMILY = DEVADDR_INET4 | DEVADDR_INET6,
  22. /* externally added address */
  23. DEVADDR_EXTERNAL = (1 << 2),
  24. /* route overrides the default interface metric */
  25. DEVROUTE_METRIC = (1 << 3),
  26. /* route overrides the default interface mtu */
  27. DEVROUTE_MTU = (1 << 4),
  28. /* route automatically added by kernel */
  29. DEVADDR_KERNEL = (1 << 5),
  30. /* address is off-link (no subnet-route) */
  31. DEVADDR_OFFLINK = (1 << 6),
  32. /* route resides in different table */
  33. DEVROUTE_TABLE = (1 << 7),
  34. /* route resides in default source-route table */
  35. DEVROUTE_SRCTABLE = (1 << 8),
  36. };
  37. union if_addr {
  38. struct in_addr in;
  39. struct in6_addr in6;
  40. };
  41. struct device_prefix_assignment {
  42. struct list_head head;
  43. int32_t assigned;
  44. uint8_t length;
  45. bool enabled;
  46. char name[];
  47. };
  48. struct device_prefix {
  49. struct vlist_node node;
  50. struct list_head head;
  51. struct list_head assignments;
  52. struct interface *iface;
  53. time_t valid_until;
  54. time_t preferred_until;
  55. struct in6_addr excl_addr;
  56. uint8_t excl_length;
  57. struct in6_addr addr;
  58. uint8_t length;
  59. char pclass[];
  60. };
  61. struct device_addr {
  62. struct vlist_node node;
  63. bool enabled;
  64. /* ipv4 only */
  65. uint32_t broadcast;
  66. uint32_t point_to_point;
  67. /* ipv6 only */
  68. time_t valid_until;
  69. time_t preferred_until;
  70. /* must be last */
  71. enum device_addr_flags flags;
  72. unsigned int mask;
  73. union if_addr addr;
  74. };
  75. struct device_route {
  76. struct vlist_node node;
  77. struct interface *iface;
  78. bool enabled;
  79. bool keep;
  80. union if_addr nexthop;
  81. int mtu;
  82. time_t valid_until;
  83. /* must be last */
  84. enum device_addr_flags flags;
  85. int metric; // there can be multiple routes to the same target
  86. unsigned int table;
  87. unsigned int mask;
  88. union if_addr addr;
  89. };
  90. struct dns_server {
  91. struct vlist_simple_node node;
  92. int af;
  93. union if_addr addr;
  94. };
  95. struct dns_search_domain {
  96. struct vlist_simple_node node;
  97. char name[];
  98. };
  99. extern const struct uci_blob_param_list route_attr_list;
  100. extern struct list_head prefixes;
  101. void interface_ip_init(struct interface *iface);
  102. void interface_add_dns_server(struct interface_ip_settings *ip, const char *str);
  103. void interface_add_dns_server_list(struct interface_ip_settings *ip, struct blob_attr *list);
  104. void interface_add_dns_search_list(struct interface_ip_settings *ip, struct blob_attr *list);
  105. void interface_write_resolv_conf(void);
  106. void interface_ip_add_route(struct interface *iface, struct blob_attr *attr, bool v6);
  107. void interface_ip_update_start(struct interface_ip_settings *ip);
  108. void interface_ip_update_complete(struct interface_ip_settings *ip);
  109. void interface_ip_flush(struct interface_ip_settings *ip);
  110. void interface_ip_set_enabled(struct interface_ip_settings *ip, bool enabled);
  111. void interface_ip_update_metric(struct interface_ip_settings *ip, int metric);
  112. struct interface *interface_ip_add_target_route(union if_addr *addr, bool v6, struct interface *iface);
  113. struct device_prefix* interface_ip_add_device_prefix(struct interface *iface,
  114. struct in6_addr *addr, uint8_t length, time_t valid_until, time_t preferred_until,
  115. struct in6_addr *excl_addr, uint8_t excl_length, const char *pclass);
  116. void interface_ip_set_ula_prefix(const char *prefix);
  117. void interface_refresh_assignments(bool hint);
  118. #endif