2
0

network.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * Copyright (C) 2022 Felix Fietkau <nbd@nbd.name>
  4. */
  5. #ifndef __UNETD_NETWORK_H
  6. #define __UNETD_NETWORK_H
  7. #include <netinet/in.h>
  8. #include <libubox/uloop.h>
  9. #include "curve25519.h"
  10. enum network_type {
  11. NETWORK_TYPE_FILE,
  12. NETWORK_TYPE_INLINE,
  13. NETWORK_TYPE_DYNAMIC,
  14. };
  15. struct wg_ops;
  16. struct network_group;
  17. struct network_host;
  18. struct network {
  19. struct avl_node node;
  20. struct wg wg;
  21. struct {
  22. struct blob_attr *data;
  23. enum network_type type;
  24. int keepalive;
  25. uint8_t key[CURVE25519_KEY_SIZE];
  26. uint8_t pubkey[CURVE25519_KEY_SIZE];
  27. uint8_t auth_key[CURVE25519_KEY_SIZE];
  28. const char *file;
  29. const char *interface;
  30. const char *update_cmd;
  31. const char *domain;
  32. struct blob_attr *tunnels;
  33. struct blob_attr *net_data;
  34. struct blob_attr *auth_connect;
  35. struct blob_attr *peer_data;
  36. } config;
  37. struct {
  38. uint64_t hash;
  39. union network_addr addr;
  40. struct network_host *local_host;
  41. unsigned int keepalive;
  42. int port;
  43. int pex_port;
  44. bool local_host_changed;
  45. struct blob_attr *stun_list;
  46. } net_config;
  47. void *net_data;
  48. size_t net_data_len;
  49. uint64_t net_data_version;
  50. int num_net_queries;
  51. struct uloop_timeout reload_timer;
  52. int ifindex;
  53. struct network_host *prev_local_host;
  54. struct list_head dynamic_peers;
  55. struct avl_tree hosts;
  56. struct vlist_tree peers;
  57. struct avl_tree groups;
  58. struct vlist_tree services;
  59. struct uloop_timeout connect_timer;
  60. struct network_pex pex;
  61. struct network_stun stun;
  62. };
  63. enum {
  64. NETWORK_ATTR_NAME,
  65. NETWORK_ATTR_TYPE,
  66. NETWORK_ATTR_KEY,
  67. NETWORK_ATTR_AUTH_KEY,
  68. NETWORK_ATTR_FILE,
  69. NETWORK_ATTR_DATA,
  70. NETWORK_ATTR_INTERFACE,
  71. NETWORK_ATTR_UPDATE_CMD,
  72. NETWORK_ATTR_KEEPALIVE,
  73. NETWORK_ATTR_DOMAIN,
  74. NETWORK_ATTR_TUNNELS,
  75. NETWORK_ATTR_AUTH_CONNECT,
  76. NETWORK_ATTR_PEER_DATA,
  77. __NETWORK_ATTR_MAX,
  78. };
  79. extern struct avl_tree networks;
  80. extern const struct blobmsg_policy network_policy[__NETWORK_ATTR_MAX];
  81. static inline const char *network_name(struct network *net)
  82. {
  83. return net->node.key;
  84. }
  85. bool network_skip_endpoint_route(struct network *net, union network_endpoint *ep);
  86. void network_fill_host_addr(union network_addr *addr, uint8_t *key);
  87. int network_save_dynamic(struct network *net);
  88. void network_soft_reload(struct network *net);
  89. void network_free_all(void);
  90. int unetd_network_add(const char *name, struct blob_attr *config);
  91. int unetd_network_remove(const char *name);
  92. #endif