interface.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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. struct buffered_update {
  20. unsigned char id[8];
  21. unsigned char prefix[16];
  22. unsigned char src_prefix[16];
  23. unsigned char plen;
  24. unsigned char src_plen; /* 0 <=> no src prefix */
  25. // -- lorauth --
  26. unsigned short clen;
  27. unsigned char cipher[514];
  28. // ----
  29. unsigned char pad[2];
  30. };
  31. #define IF_TYPE_DEFAULT 0
  32. #define IF_TYPE_WIRED 1
  33. #define IF_TYPE_WIRELESS 2
  34. #define IF_TYPE_TUNNEL 3
  35. /* If you modify this structure, also modify the merge_ifconf function. */
  36. struct interface_conf {
  37. char *ifname;
  38. unsigned hello_interval;
  39. unsigned update_interval;
  40. unsigned short cost;
  41. char type;
  42. char split_horizon;
  43. char lq;
  44. char faraway;
  45. int channel;
  46. int enable_timestamps;
  47. unsigned int rtt_decay;
  48. unsigned int rtt_min;
  49. unsigned int rtt_max;
  50. unsigned int max_rtt_penalty;
  51. struct interface_conf *next;
  52. };
  53. #define CONFIG_DEFAULT 0
  54. #define CONFIG_NO 1
  55. #define CONFIG_YES 2
  56. /* Interface is up. */
  57. # define IF_UP (1 << 0)
  58. /* Interface known to be wireless, unknown otherwise. */
  59. #define IF_WIRELESS (1<<1)
  60. /* Apply split horizon. */
  61. #define IF_SPLIT_HORIZON (1 << 2)
  62. /* Perform link-quality estimation. */
  63. #define IF_LQ (1 << 3)
  64. /* Nodes on the far end don't interfere with nodes on the near end. */
  65. #define IF_FARAWAY (1 << 4)
  66. /* Send timestamps in Hello and IHU. */
  67. #define IF_TIMESTAMPS (1 << 5)
  68. /* Only INTERFERING can appear on the wire. */
  69. #define IF_CHANNEL_UNKNOWN 0
  70. #define IF_CHANNEL_INTERFERING 255
  71. #define IF_CHANNEL_NONINTERFERING -2
  72. struct interface {
  73. struct interface *next;
  74. struct interface_conf *conf;
  75. unsigned int ifindex;
  76. unsigned short flags;
  77. unsigned short cost;
  78. int channel;
  79. struct timeval hello_timeout;
  80. struct timeval update_timeout;
  81. struct timeval flush_timeout;
  82. struct timeval update_flush_timeout;
  83. char name[IF_NAMESIZE];
  84. unsigned char *ipv4;
  85. int numll;
  86. unsigned char (*ll)[16];
  87. int buffered;
  88. int bufsize;
  89. /* Relative position of the Hello message in the send buffer, or
  90. (-1) if there is none. */
  91. int buffered_hello;
  92. char have_buffered_id;
  93. char have_buffered_nh;
  94. char have_buffered_prefix;
  95. // -- lorauth --
  96. char have_buffered_cipher;
  97. // ----
  98. unsigned char buffered_id[8];
  99. unsigned char buffered_nh[4];
  100. unsigned char buffered_prefix[16];
  101. unsigned char *sendbuf;
  102. struct buffered_update *buffered_updates;
  103. int num_buffered_updates;
  104. int update_bufsize;
  105. time_t bucket_time;
  106. unsigned int bucket;
  107. time_t last_update_time;
  108. time_t last_specific_update_time;
  109. unsigned short hello_seqno;
  110. unsigned hello_interval;
  111. unsigned update_interval;
  112. /* A higher value means we forget old RTT samples faster. Must be
  113. between 1 and 256, inclusive. */
  114. unsigned int rtt_decay;
  115. /* Parameters for computing the cost associated to RTT. */
  116. unsigned int rtt_min;
  117. unsigned int rtt_max;
  118. unsigned int max_rtt_penalty;
  119. };
  120. #define IF_CONF(_ifp, _field) \
  121. ((_ifp)->conf ? (_ifp)->conf->_field : 0)
  122. extern struct interface *interfaces;
  123. #define FOR_ALL_INTERFACES(_ifp) for(_ifp = interfaces; _ifp; _ifp = _ifp->next)
  124. static inline int
  125. if_up(struct interface *ifp)
  126. {
  127. return !!(ifp->flags & IF_UP);
  128. }
  129. struct interface *add_interface(char *ifname, struct interface_conf *if_conf);
  130. int flush_interface(char *ifname);
  131. unsigned jitter(struct interface *ifp, int urgent);
  132. unsigned update_jitter(struct interface *ifp, int urgent);
  133. void set_timeout(struct timeval *timeout, int msecs);
  134. int interface_up(struct interface *ifp, int up);
  135. int interface_ll_address(struct interface *ifp, const unsigned char *address);
  136. void check_interfaces(void);