rtadv.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  1. /* Router advertisement
  2. * Copyright (C) 2005 6WIND <jean-mickael.guerin@6wind.com>
  3. * Copyright (C) 1999 Kunihiro Ishiguro
  4. *
  5. * This file is part of GNU Zebra.
  6. *
  7. * GNU Zebra is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU General Public License as published by the
  9. * Free Software Foundation; either version 2, or (at your option) any
  10. * later version.
  11. *
  12. * GNU Zebra is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with GNU Zebra; see the file COPYING. If not, write to the Free
  19. * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
  20. * 02111-1307, USA.
  21. */
  22. #ifndef _ZEBRA_RTADV_H
  23. #define _ZEBRA_RTADV_H
  24. #include "vty.h"
  25. #include "linklist.h"
  26. #include "if.h"
  27. /* zebra_vrf left incomplete, as it is defined in rib.h and rib.h at present
  28. * needs (struct rtadv) as a complete type to embed it in (struct zebra_vrf)
  29. */
  30. struct zebra_vrf;
  31. /* "ipv6 nd connected-prefix ..." feature parameters */
  32. struct rtadv_connprefix
  33. {
  34. u_int32_t AdvValidLifetime;
  35. u_int32_t AdvPreferredLifetime;
  36. u_char AdvAutonomousFlag;
  37. u_char AdvOnLinkFlag;
  38. };
  39. /* Router advertisement parameter. From RFC4861, RFC6275 and RFC4191. */
  40. struct rtadvconf
  41. {
  42. /* A flag indicating whether or not the router sends periodic Router
  43. Advertisements and responds to Router Solicitations.
  44. 0: disabled, 1: enabled, -1: use current router-scope parameter
  45. Default: -1 */
  46. int AdvSendAdvertisements;
  47. /* The maximum time allowed between sending unsolicited multicast
  48. Router Advertisements from the interface, in milliseconds.
  49. MUST be no less than 70 ms [RFC6275 7.5] and no greater
  50. than 1800000 ms [RFC4861 6.2.1].
  51. Default: 600000 milliseconds */
  52. int MaxRtrAdvInterval;
  53. #define RTADV_MAX_RTR_ADV_INTERVAL 600000
  54. /* The minimum time allowed between sending unsolicited multicast
  55. Router Advertisements from the interface, in milliseconds.
  56. MUST be no less than 30 ms [RFC6275 7.5].
  57. MUST be no greater than .75 * MaxRtrAdvInterval.
  58. Default: 0.33 * MaxRtrAdvInterval */
  59. int MinRtrAdvInterval; /* This field is currently unused. */
  60. #define RTADV_MIN_RTR_ADV_INTERVAL (0.33 * RTADV_MAX_RTR_ADV_INTERVAL)
  61. /* Unsolicited Router Advertisements' interval timer. */
  62. int AdvIntervalTimer;
  63. /* The TRUE/FALSE value to be placed in the "Managed address
  64. configuration" flag field in the Router Advertisement. See
  65. [ADDRCONF].
  66. Default: FALSE */
  67. int AdvManagedFlag;
  68. /* The TRUE/FALSE value to be placed in the "Other stateful
  69. configuration" flag field in the Router Advertisement. See
  70. [ADDRCONF].
  71. Default: FALSE */
  72. int AdvOtherConfigFlag;
  73. /* The value to be placed in MTU options sent by the router. A
  74. value of zero indicates that no MTU options are sent.
  75. Default: 0 */
  76. int AdvLinkMTU;
  77. /* The value to be placed in the Reachable Time field in the Router
  78. Advertisement messages sent by the router. The value zero means
  79. unspecified (by this router). MUST be no greater than 3,600,000
  80. milliseconds (1 hour).
  81. Default: 0 */
  82. u_int32_t AdvReachableTime;
  83. #define RTADV_MAX_REACHABLE_TIME 3600000
  84. /* The value to be placed in the Retrans Timer field in the Router
  85. Advertisement messages sent by the router. The value zero means
  86. unspecified (by this router).
  87. Default: 0 */
  88. int AdvRetransTimer;
  89. /* The default value to be placed in the Cur Hop Limit field in the
  90. Router Advertisement messages sent by the router. The value
  91. should be set to that current diameter of the Internet. The
  92. value zero means unspecified (by this router).
  93. Default: The value specified in the "Assigned Numbers" RFC
  94. [ASSIGNED] that was in effect at the time of implementation. */
  95. int AdvCurHopLimit;
  96. /* The value to be placed in the Router Lifetime field of Router
  97. Advertisements sent from the interface, in seconds. MUST be
  98. either zero or between MaxRtrAdvInterval and 9000 seconds. A
  99. value of zero indicates that the router is not to be used as a
  100. default router.
  101. Default: 3 * MaxRtrAdvInterval */
  102. int AdvDefaultLifetime;
  103. #define RTADV_MAX_RTRLIFETIME 9000 /* 2.5 hours */
  104. /* A list of prefixes to be placed in Prefix Information options in
  105. Router Advertisement messages sent from the interface.
  106. Default: all prefixes that the router advertises via routing
  107. protocols as being on-link for the interface from which the
  108. advertisement is sent. The link-local prefix SHOULD NOT be
  109. included in the list of advertised prefixes. */
  110. struct list *AdvPrefixList;
  111. /* The TRUE/FALSE value to be placed in the "Home agent"
  112. flag field in the Router Advertisement. See [RFC6275 7.1].
  113. Default: FALSE */
  114. int AdvHomeAgentFlag;
  115. #ifndef ND_RA_FLAG_HOME_AGENT
  116. #define ND_RA_FLAG_HOME_AGENT 0x20
  117. #endif
  118. /* The value to be placed in Home Agent Information option if Home
  119. Flag is set.
  120. Default: 0 */
  121. int HomeAgentPreference;
  122. /* The value to be placed in Home Agent Information option if Home
  123. Flag is set. Lifetime (seconds) MUST not be greater than 18.2
  124. hours.
  125. The value 0 has special meaning: use of AdvDefaultLifetime value.
  126. Default: 0 */
  127. int HomeAgentLifetime;
  128. #define RTADV_MAX_HALIFETIME 65520 /* 18.2 hours */
  129. /* The TRUE/FALSE value to insert or not an Advertisement Interval
  130. option. See [RFC 6275 7.3]
  131. Default: FALSE */
  132. int AdvIntervalOption;
  133. /* The value to be placed in the Default Router Preference field of
  134. a router advertisement. See [RFC 4191 2.1 & 2.2]
  135. Default: 0 (medium) */
  136. int DefaultPreference;
  137. /* RFC4191 2.1. Preference Values: "Preference values are encoded as
  138. a two-bit signed integer, as follows:" */
  139. #define RTADV_PREF_HIGH 0x1 /* 01 High */
  140. #define RTADV_PREF_MEDIUM 0x0 /* 00 Medium (default) */
  141. #define RTADV_PREF_RESERVED 0x2 /* 10 Reserved - MUST NOT be sent */
  142. #define RTADV_PREF_LOW 0x3 /* 11 Low */
  143. /* A list of Recursive DNS server addresses specified in
  144. RFC 6106 */
  145. struct list *AdvRDNSSList;
  146. #define RTADV_DNS_INFINITY_LIFETIME (0xffffffff)
  147. #define RTADV_DNS_OBSOLETE_LIFETIME (0x00000000)
  148. /* a list of configured DNS Search List domains (RFC6106) */
  149. struct list *AdvDNSSLList;
  150. /* interface-scope setting: 0: disabled, 1: enabled, -1: use current
  151. * router-scope parameter. Default: -1 */
  152. char ConnpfxEnabled;
  153. struct rtadv_connprefix ConnpfxConfig;
  154. };
  155. /* NB: RTADV is defined in zebra/interface.h above */
  156. #if defined (HAVE_RTADV)
  157. /* Router advertisement prefix. */
  158. struct rtadv_prefix
  159. {
  160. /* Prefix to be advertised. */
  161. struct prefix_ipv6 prefix;
  162. /* The value to be placed in the Valid Lifetime in the Prefix */
  163. u_int32_t AdvValidLifetime;
  164. #define RTADV_VALID_LIFETIME 2592000
  165. /* The value to be placed in the on-link flag */
  166. int AdvOnLinkFlag;
  167. /* The value to be placed in the Preferred Lifetime in the Prefix
  168. Information option, in seconds.*/
  169. u_int32_t AdvPreferredLifetime;
  170. #define RTADV_PREFERRED_LIFETIME 604800
  171. /* The value to be placed in the Autonomous Flag. */
  172. int AdvAutonomousFlag;
  173. /* The value to be placed in the Router Address Flag [RFC6275 7.2]. */
  174. int AdvRouterAddressFlag;
  175. #ifndef ND_OPT_PI_FLAG_RADDR
  176. #define ND_OPT_PI_FLAG_RADDR 0x20
  177. #endif
  178. };
  179. /* RFC4584 Extension to Sockets API for Mobile IPv6 */
  180. #ifndef ND_OPT_ADV_INTERVAL
  181. #define ND_OPT_ADV_INTERVAL 7 /* Adv Interval Option */
  182. #endif
  183. #ifndef ND_OPT_HA_INFORMATION
  184. #define ND_OPT_HA_INFORMATION 8 /* HA Information Option */
  185. #endif
  186. #ifndef ND_OPT_RDNSS
  187. #define ND_OPT_RDNSS 25 /* Recursive DNS Server Option (RFC 6106) */
  188. #endif
  189. #ifndef ND_OPT_DNSSL
  190. #define ND_OPT_DNSSL 31 /* DNS Search List Option (RFC6106) */
  191. #endif
  192. #ifndef HAVE_STRUCT_ND_OPT_ADV_INTERVAL
  193. struct nd_opt_adv_interval { /* Advertisement interval option */
  194. uint8_t nd_opt_ai_type;
  195. uint8_t nd_opt_ai_len;
  196. uint16_t nd_opt_ai_reserved;
  197. uint32_t nd_opt_ai_interval;
  198. } __attribute__((__packed__));
  199. #else
  200. #ifndef HAVE_STRUCT_ND_OPT_ADV_INTERVAL_ND_OPT_AI_TYPE
  201. /* fields may have to be renamed */
  202. #define nd_opt_ai_type nd_opt_adv_interval_type
  203. #define nd_opt_ai_len nd_opt_adv_interval_len
  204. #define nd_opt_ai_reserved nd_opt_adv_interval_reserved
  205. #define nd_opt_ai_interval nd_opt_adv_interval_ival
  206. #endif
  207. #endif
  208. #ifndef HAVE_STRUCT_ND_OPT_HOMEAGENT_INFO
  209. struct nd_opt_homeagent_info { /* Home Agent info */
  210. u_int8_t nd_opt_hai_type;
  211. u_int8_t nd_opt_hai_len;
  212. u_int16_t nd_opt_hai_reserved;
  213. u_int16_t nd_opt_hai_preference;
  214. u_int16_t nd_opt_hai_lifetime;
  215. } __attribute__((__packed__));
  216. #endif
  217. #ifndef HAVE_STRUCT_ND_OPT_RDNSS
  218. /* see RFC 6106, section 5.1 */
  219. struct nd_opt_rdnss {
  220. uint8_t nd_opt_rdnss_type;
  221. uint8_t nd_opt_rdnss_len;
  222. uint16_t nd_opt_rdnss_reserved;
  223. uint32_t nd_opt_rdnss_lifetime;
  224. /* followed by n (16 byte) entries */
  225. } __attribute__((__packed__));
  226. #endif
  227. /* for internal tracking of configured RDNSS entries */
  228. struct rtadv_rdnss_entry
  229. {
  230. struct in6_addr address;
  231. u_char track_maxrai;
  232. u_int32_t lifetime;
  233. };
  234. #ifndef HAVE_STRUCT_ND_OPT_DNSSL
  235. struct nd_opt_dnssl
  236. {
  237. u_int8_t nd_opt_dnssl_type;
  238. u_int8_t nd_opt_dnssl_len;
  239. u_int16_t nd_opt_dnssl_reserved;
  240. u_int32_t nd_opt_dnssl_lifetime;
  241. /* followed by list of DNS search domains */
  242. } __attribute__((__packed__));
  243. #endif
  244. /* RFC1035 sets the maximum length of a label-encoded domain name to 255 bytes,
  245. * which stand for 253 non-0 chars of the NULL-terminated string representation,
  246. * one trailing 0 byte and one extra "length" byte before the last label, which
  247. * is not set off with a '.' byte of the respective input word (trailing "root"
  248. * dot is considered a syntax error in this implementation). */
  249. #define SUBDOMAIN_MAX_STRLEN 253
  250. /* for internal tracking of configured DNSSL entries */
  251. struct rtadv_dnssl_entry
  252. {
  253. char subdomain_str[SUBDOMAIN_MAX_STRLEN + 1];
  254. u_int8_t subdomain_rfc1035[SUBDOMAIN_MAX_STRLEN + 2];
  255. u_char length_rfc1035;
  256. u_char track_maxrai;
  257. u_int32_t lifetime;
  258. };
  259. /* Structure which hold status of router advertisement. */
  260. struct rtadv
  261. {
  262. int sock;
  263. int adv_if_count;
  264. int adv_msec_if_count;
  265. struct thread *ra_read;
  266. struct thread *ra_timer;
  267. /* router-scope setting; 0: disabled, 1: enabled */
  268. u_char AdvSendAdvertisements;
  269. /* router-scope RDNSS options */
  270. struct list *AdvRDNSSList;
  271. /* router-scope DNSSL options */
  272. struct list *AdvDNSSLList;
  273. /* router-scope setting */
  274. u_char ConnpfxEnabled;
  275. struct rtadv_connprefix ConnpfxConfig;
  276. };
  277. #endif /* HAVE_RTADV */
  278. extern void rtadv_config_write (struct vty *, struct interface *);
  279. extern void rtadv_init (struct zebra_vrf *);
  280. extern void rtadv_terminate (struct zebra_vrf *);
  281. extern void rtadv_cmd_init (void);
  282. /* Router advertisement feature. */
  283. #ifdef HAVE_RTADV
  284. extern void rtadv_if_dump_vty (struct vty *, struct interface *);
  285. extern void rtadv_if_new_hook (struct rtadvconf *);
  286. extern void rtadv_refresh_connected (struct interface *);
  287. #endif
  288. #endif /* _ZEBRA_RTADV_H */