Advertisement
upyzl

RADVD 1.8.5 Add option (test)

Apr 4th, 2012
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 8.92 KB | None | 0 0
  1. diff --git a/defaults.h b/defaults.h
  2. index 89cd7f7..d2e2b8d 100644
  3. --- a/defaults.h
  4. +++ b/defaults.h
  5. @@ -58,6 +58,11 @@
  6.  #define DFLT_DeprecatePrefixFlag   0
  7.  #define DFLT_DecrementLifetimesFlag    0
  8.  
  9. +/* Tele Option Initial Define */
  10. +#define DFLT_AdvTeleFlag       1
  11. +#define DFLT_AdvTeleLifetime       43200 /* seconds */
  12. +#define DFLT_RemoveTeleFlag        1
  13. +
  14.  /* Each route has an associated: */
  15.  #define DFLT_AdvRouteLifetime(iface)   (3 * (iface)->MaxRtrAdvInterval)
  16.  
  17. @@ -152,6 +157,11 @@
  18.  #undef ND_OPT_ROUTE_INFORMATION
  19.  #define  ND_OPT_ROUTE_INFORMATION  24
  20.  
  21. +/* New custom type */
  22. +#ifndef ND_OPT_TELE_INFORMATION
  23. +#define ND_OPT_TELE_INFORMATION    200
  24. +#endif
  25. +
  26.  /* XXX: some libc's like KAME already had nd_opt_route_info! */
  27.  struct nd_opt_route_info_local     /* route information */
  28.    {
  29. @@ -163,6 +173,17 @@ struct nd_opt_route_info_local     /* route information */
  30.      struct in6_addr  nd_opt_ri_prefix;
  31.    };
  32.  
  33. +/* Custom tele info */
  34. +struct nd_opt_tele_info_local     /* tele information */
  35. +  {
  36. +    uint8_t   nd_opt_tl_type;
  37. +    uint8_t   nd_opt_tl_len;
  38. +    uint8_t   nd_opt_tl_prefix_len;
  39. +    uint8_t   nd_opt_tl_flags_reserved;
  40. +    uint32_t  nd_opt_tl_lifetime;
  41. +    struct in6_addr  nd_opt_tl_prefix;
  42. +  };
  43. +
  44.  /* the reserved field is 8 bits and we're interested of the middle two: 000xx000 */
  45.  #define ND_OPT_RI_PRF_SHIFT    3
  46.  #define ND_OPT_RI_PRF_MASK (3 << ND_OPT_RI_PRF_SHIFT) /* 00011000 = 0x18 */
  47. diff --git a/gram.y b/gram.y
  48. index 43f3c29..ed8589d 100644
  49. --- a/gram.y
  50. +++ b/gram.y
  51. @@ -21,6 +21,7 @@
  52.  extern struct Interface *IfaceList;
  53.  struct Interface *iface = NULL;
  54.  struct AdvPrefix *prefix = NULL;
  55. +struct AdvTele  *tele = NULL;
  56.  struct AdvRoute *route = NULL;
  57.  struct AdvRDNSS *rdnss = NULL;
  58.  struct AdvDNSSL *dnssl = NULL;
  59. @@ -62,6 +63,7 @@ static struct in6_addr get_prefix6(struct in6_addr const *addr, struct in6_addr
  60.  
  61.  %token     T_INTERFACE
  62.  %token     T_PREFIX
  63. +%token     T_TELE
  64.  %token     T_ROUTE
  65.  %token     T_RDNSS
  66.  %token     T_DNSSL
  67. @@ -109,6 +111,10 @@ static struct in6_addr get_prefix6(struct in6_addr const *addr, struct in6_addr
  68.  %token     T_HomeAgentPreference
  69.  %token     T_HomeAgentLifetime
  70.  
  71. +%token     T_AdvTeleFlag
  72. +%token     T_AdvTeleLifetime
  73. +%token     T_RemoveTeleFlag
  74. +
  75.  %token     T_AdvRoutePreference
  76.  %token     T_AdvRouteLifetime
  77.  %token     T_RemoveRoute
  78. @@ -128,6 +134,7 @@ static struct in6_addr get_prefix6(struct in6_addr const *addr, struct in6_addr
  79.  %type  <str>   name
  80.  %type  <pinfo> prefixdef
  81.  %type  <ainfo> clientslist v6addrlist
  82. +%type  <tinfo> teledef
  83.  %type  <rinfo> routedef
  84.  %type  <rdnssinfo> rdnssdef
  85.  %type  <dnsslinfo> dnssldef
  86. @@ -140,6 +147,7 @@ static struct in6_addr get_prefix6(struct in6_addr const *addr, struct in6_addr
  87.     struct in6_addr     *addr;
  88.     char            *str;
  89.     struct AdvPrefix    *pinfo;
  90. +   struct AdvTele      *tinfo;
  91.     struct AdvRoute     *rinfo;
  92.     struct AdvRDNSS     *rdnssinfo;
  93.     struct AdvDNSSL     *dnsslinfo;
  94. @@ -228,6 +236,7 @@ ifaceparams :
  95.  ifaceparam     : ifaceval
  96.         | prefixdef     { ADD_TO_LL(struct AdvPrefix, AdvPrefixList, $1); }
  97.         | clientslist   { ADD_TO_LL(struct Clients, ClientList, $1); }
  98. +       | teledef       { ADD_TO_LL(struct AdvTele, AdvTeleList, $1); }
  99.         | routedef  { ADD_TO_LL(struct AdvRoute, AdvRouteList, $1); }
  100.         | rdnssdef  { ADD_TO_LL(struct AdvRDNSS, AdvRDNSSList, $1); }
  101.         | dnssldef  { ADD_TO_LL(struct AdvDNSSL, AdvDNSSLList, $1); }
  102. @@ -726,6 +735,58 @@ routeparms : T_AdvRoutePreference SIGNEDNUMBER ';'
  103.         }
  104.         ;
  105.  
  106. +teledef    : telehead '{' optional_teleplist '}' ';'
  107. +       {
  108. +           $$ = tele;
  109. +           tele = NULL;
  110. +       }
  111. +       ;
  112. +
  113. +telehead   : T_TELE IPV6ADDR '/' NUMBER
  114. +       {
  115. +           tele = malloc(sizeof(struct AdvTele));
  116. +
  117. +           if (tele == NULL) {
  118. +               flog(LOG_CRIT, "malloc failed: %s", strerror(errno));
  119. +               ABORT;
  120. +           }
  121. +
  122. +           tele_init_defaults(tele);
  123. +
  124. +           if ($4 > MAX_PrefixLen)
  125. +           {
  126. +               flog(LOG_ERR, "invalid tele prefix length in %s, line %d", conf_file, num_lines);
  127. +               ABORT;
  128. +           }
  129. +
  130. +           tele->PrefixLen = $4;
  131. +
  132. +           memcpy(&tele->Prefix, $2, sizeof(struct in6_addr));
  133. +       }
  134. +       ;
  135. +
  136. +optional_teleplist: /* empty */
  137. +       | teleplist
  138. +       ;
  139. +
  140. +teleplist  : teleplist teleparms
  141. +       | teleparms
  142. +       ;
  143. +
  144. +teleparms  : T_AdvTeleFlag SWITCH ';'
  145. +       {
  146. +           tele->AdvTeleFlag = $2;
  147. +       }
  148. +       | T_AdvTeleLifetime number_or_infinity ';'
  149. +       {
  150. +           tele->AdvTeleLifetime = $2;
  151. +       }
  152. +       | T_RemoveTeleFlag SWITCH ';'
  153. +       {
  154. +           tele->RemoveTeleFlag = $2;
  155. +       }
  156. +       ;
  157. +      
  158.  rdnssdef   : rdnsshead '{' optional_rdnssplist '}' ';'
  159.         {
  160.             $$ = rdnss;
  161. @@ -962,6 +1023,9 @@ void cleanup(void)
  162.     if (prefix)
  163.         free(prefix);
  164.  
  165. +   if (tele)
  166. +       free(tele);
  167. +
  168.     if (route)
  169.         free(route);
  170.  
  171. diff --git a/interface.c b/interface.c
  172. index d17267e..32649c8 100644
  173. --- a/interface.c
  174. +++ b/interface.c
  175. @@ -66,6 +66,16 @@ prefix_init_defaults(struct AdvPrefix *prefix)
  176.  }
  177.  
  178.  void
  179. +tele_init_defaults(struct AdvTele *tele)
  180. +{
  181. +   memset(tele, 0, sizeof(struct AdvTele));
  182. +
  183. +   tele->AdvTeleFlag = DFLT_AdvTeleFlag;
  184. +   tele->AdvTeleLifetime = DFLT_AdvTeleLifetime;
  185. +   tele->RemoveTeleFlag = DFLT_RemoveTeleFlag;
  186. +}
  187. +
  188. +void
  189.  route_init_defaults(struct AdvRoute *route, struct Interface *iface)
  190.  {
  191.     memset(route, 0, sizeof(struct AdvRoute));
  192. diff --git a/radvd.c b/radvd.c
  193. index 111c21c..2886b25 100644
  194. --- a/radvd.c
  195. +++ b/radvd.c
  196. @@ -576,6 +576,7 @@ void reload_config(void)
  197.     {
  198.         struct Interface *next_iface = iface->next;
  199.         struct AdvPrefix *prefix;
  200. +       struct AdvTele   *tele;
  201.         struct AdvRoute *route;
  202.         struct AdvRDNSS *rdnss;
  203.         struct AdvDNSSL *dnssl;
  204. @@ -600,6 +601,15 @@ void reload_config(void)
  205.             route = next_route;
  206.         }
  207.  
  208. +       tele = iface->AdvTeleList;
  209. +       while (tele)
  210. +       {
  211. +           struct AdvTele *next_tele = tele->next;
  212. +
  213. +           free(tele);
  214. +           tele = next_tele;
  215. +       }
  216. +
  217.         rdnss = iface->AdvRDNSSList;
  218.         while (rdnss)
  219.         {
  220. diff --git a/radvd.h b/radvd.h
  221. index d1304f4..ba5bc7c 100644
  222. --- a/radvd.h
  223. +++ b/radvd.h
  224. @@ -77,6 +77,7 @@ struct Interface {
  225.     int         AdvMobRtrSupportFlag;
  226.  
  227.     struct AdvPrefix    *AdvPrefixList;
  228. +   struct AdvTele     *AdvTeleList;
  229.     struct AdvRoute     *AdvRouteList;
  230.     struct AdvRDNSS     *AdvRDNSSList;
  231.     struct AdvDNSSL     *AdvDNSSLList;
  232. @@ -123,6 +124,19 @@ struct AdvPrefix {
  233.     struct AdvPrefix    *next;
  234.  };
  235.  
  236. +/* Custom Option for ICMPv6 RS&RA */
  237. +
  238. +struct AdvTele {
  239. +   struct in6_addr     Prefix;
  240. +   uint8_t         PrefixLen;
  241. +
  242. +   int         AdvTeleFlag;
  243. +   uint32_t        AdvTeleLifetime;
  244. +   int         RemoveTeleFlag;
  245. +
  246. +   struct AdvTele      *next;
  247. +};
  248. +
  249.  /* More-Specific Routes extensions */
  250.  
  251.  struct AdvRoute {
  252. @@ -210,6 +224,7 @@ int set_interface_retranstimer(const char *, uint32_t);
  253.  /* interface.c */
  254.  void iface_init_defaults(struct Interface *);
  255.  void prefix_init_defaults(struct AdvPrefix *);
  256. +void tele_init_defaults(struct AdvTele *);
  257.  void route_init_defaults(struct AdvRoute *, struct Interface *);
  258.  void rdnss_init_defaults(struct AdvRDNSS *, struct Interface *);
  259.  void dnssl_init_defaults(struct AdvDNSSL *, struct Interface *);
  260. diff --git a/scanner.l b/scanner.l
  261. index c2f68cd..fa07364 100644
  262. --- a/scanner.l
  263. +++ b/scanner.l
  264. @@ -45,6 +45,7 @@ string        [a-zA-Z0-9`~!@#$%\^&*()_\-+=:\[\]<>,\.?\\]+
  265.  
  266.  interface      { return T_INTERFACE; }
  267.  prefix         { return T_PREFIX; }
  268. +tele           { return T_TELE; }
  269.  route          { return T_ROUTE; }
  270.  RDNSS          { return T_RDNSS; }
  271.  DNSSL          { return T_DNSSL; }
  272. @@ -83,6 +84,10 @@ Base6to4Interface    { return T_Base6to4Interface; }
  273.  HomeAgentPreference    { return T_HomeAgentPreference; }
  274.  HomeAgentLifetime  { return T_HomeAgentLifetime; }
  275.  
  276. +AdvTeleFlag    { return T_AdvTeleFlag; }
  277. +AdvTeleLifetime    { return T_AdvTeleLifetime; }
  278. +RemoveTeleFlag { return T_RemoveTeleFlag; }
  279. +
  280.  AdvRoutePreference { return T_AdvRoutePreference; }
  281.  AdvRouteLifetime   { return T_AdvRouteLifetime; }
  282.  RemoveRoute        { return T_RemoveRoute; }
  283. diff --git a/send.c b/send.c
  284. index 9e6a29c..afc3ab2 100644
  285. --- a/send.c
  286. +++ b/send.c
  287. @@ -125,6 +125,7 @@ send_ra(struct Interface *iface, struct in6_addr *dest)
  288.     struct AdvRoute *route;
  289.     struct AdvRDNSS *rdnss;
  290.     struct AdvDNSSL *dnssl;
  291. +   struct AdvTele *tele;
  292.     struct timeval time_now;
  293.     time_t secs_since_last_ra;
  294.  
  295. @@ -268,6 +269,39 @@ send_ra(struct Interface *iface, struct in6_addr *dest)
  296.         prefix = prefix->next;
  297.     }
  298.  
  299. +   tele = iface->AdvTeleList;
  300. +
  301. +   /*
  302. +    *  add Tele options
  303. +    */
  304. +
  305. +   while(tele)
  306. +   {
  307. +       struct nd_opt_tele_info_local *tinfo;
  308. +
  309. +       tinfo = (struct nd_opt_tele_info_local *) (buff + len);
  310. +
  311. +       send_ra_inc_len(&len, sizeof(*tinfo));
  312. +
  313. +       tinfo->nd_opt_tl_type        = ND_OPT_TELE_INFORMATION;
  314. +       /* New custom items */
  315. +       tinfo->nd_opt_tl_len         = 3;
  316. +       tinfo->nd_opt_tl_prefix_len  = tele->PrefixLen;
  317. +
  318. +       tinfo->nd_opt_tl_flags_reserved  =
  319. +           (tele->AdvTeleFlag << ND_OPT_RI_PRF_SHIFT) & ND_OPT_RI_PRF_MASK;
  320. +       if (iface->cease_adv && tele->RemoveTeleFlag) {
  321. +           tinfo->nd_opt_tl_lifetime   = 0;
  322. +       } else {
  323. +           tinfo->nd_opt_tl_lifetime   = htonl(tele->AdvTeleLifetime);
  324. +       }
  325. +
  326. +       memcpy(&tinfo->nd_opt_tl_prefix, &tele->Prefix,
  327. +              sizeof(struct in6_addr));
  328. +
  329. +       tele = tele->next;
  330. +   }
  331. +
  332.     route = iface->AdvRouteList;
  333.  
  334.     /*
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement