rttable-default: (from otti) configures a new policy routing table for the default...
authorSven-Ola Tuecke <sven-ola@gmx.de>
Wed, 2 Jan 2008 13:41:35 +0000 (14:41 +0100)
committerSven-Ola Tuecke <sven-ola@gmx.de>
Wed, 2 Jan 2008 13:41:35 +0000 (14:41 +0100)
lib/httpinfo/src/olsrd_httpinfo.c
src/cfgparser/cfgfile_gen.c
src/cfgparser/olsrd_conf.c
src/cfgparser/oparse.y
src/cfgparser/oscan.lex
src/linux/kernel_routes.c
src/olsr_cfg.h

index c2bddee..d43116c 100644 (file)
@@ -853,6 +853,7 @@ static int build_config_body(char *buf, olsr_u32_t bufsize)
     size += snprintf(&buf[size], bufsize-size, "<td>Fisheye: %s</td>\n", olsr_cnf->lq_fish ? "Enabled" : "Disabled");
     size += snprintf(&buf[size], bufsize-size, "<td>TOS: 0x%04x</td>\n", olsr_cnf->tos);
     size += snprintf(&buf[size], bufsize-size, "<td>RtTable: 0x%04x/%d</td>\n", olsr_cnf->rttable, olsr_cnf->rttable);
+    size += snprintf(&buf[size], bufsize-size, "<td>RtTableDefault: 0x%04x/%d</td>\n", olsr_cnf->rttable_default, olsr_cnf->rttable_default);
     size += snprintf(&buf[size], bufsize-size, "<td>Willingness: %d %s</td>\n", olsr_cnf->willingness, olsr_cnf->willingness_auto ? "(auto)" : "");
 
     if (olsr_cnf->lq_level == 0) {
index 26047b1..a592fe0 100644 (file)
@@ -110,6 +110,10 @@ olsrd_write_cnf(struct olsrd_config *cnf, const char *fname)
   fprintf(fd, "# Policy Routing Table to use. Default is 254\n\n");
   fprintf(fd, "RtTable\t\t%d\n\n", cnf->rttable);
 
+  /* RtTableDefault */
+  fprintf(fd, "# Policy Routing Table to use for the default Route. Default is 0 (Take the same table as specified by RtTable)\n\n");
+  fprintf(fd, "RtTableDefault\t\t%d\n\n", cnf->rttable_default);
+
   /* Willingness */
   fprintf(fd, "# The fixed willingness to use(0-7)\n# If not set willingness will be calculated\n# dynammically based on battery/power status\n\n");
   if(cnf->willingness_auto)
index abf1b9e..4e205da 100644 (file)
@@ -444,6 +444,7 @@ set_default_cnf(struct olsrd_config *cnf)
     cnf->allow_no_interfaces = DEF_ALLOW_NO_INTS;
     cnf->tos = DEF_TOS;
     cnf->rttable = 254;
+    cnf->rttable_default = 0;
     cnf->willingness_auto = DEF_WILL_AUTO;
     cnf->ipc_connections = DEF_IPC_CONNECTIONS;
     cnf->fib_metric = DEF_FIB_METRIC;
@@ -551,6 +552,7 @@ olsrd_print_cnf(struct olsrd_config *cnf)
     printf("No interfaces    : NOT ALLOWED\n");
   printf("TOS              : 0x%02x\n", cnf->tos);
   printf("RtTable          : 0x%02x\n", cnf->rttable);
+  printf("RtTableDefault   : 0x%02x\n", cnf->rttable_default);
   if(cnf->willingness_auto)
     printf("Willingness      : AUTO\n");
   else
index e3e54cf..a107e74 100644 (file)
@@ -173,6 +173,7 @@ static int add_ipv6_addr(YYSTYPE ipaddr_arg, YYSTYPE prefixlen_arg)
 %token TOK_NOINT
 %token TOK_TOS
 %token TOK_RTTABLE
+%token TOK_RTTABLE_DEFAULT
 %token TOK_WILLINGNESS
 %token TOK_IPCCON
 %token TOK_FIBMETRIC
@@ -231,6 +232,7 @@ stmt:       idebug
           | bnoint
           | atos
           | arttable
+          | arttable_default
           | awillingness
           | busehyst
           | fhystscale
@@ -874,6 +876,14 @@ arttable: TOK_RTTABLE TOK_INTEGER
 }
 ;
 
+arttable_default: TOK_RTTABLE_DEFAULT TOK_INTEGER
+{
+  PARSER_DEBUG_PRINTF("RtTableDefault: %d\n", $2->integer);
+  olsr_cnf->rttable_default = $2->integer;
+  free($2);
+}
+;
+
 awillingness: TOK_WILLINGNESS TOK_INTEGER
 {
   PARSER_DEBUG_PRINTF("Willingness: %d\n", $2->integer);
index 9ce27b0..7519098 100644 (file)
@@ -312,6 +312,11 @@ IPV6ADDR {IP6PAT1}|{IP6PAT2}|{IP6PAT3}|{IP6PAT4}|{IP6PAT5}|{IP6PAT6}|{IP6PAT7}|{
   return TOK_RTTABLE;
 }
 
+"RtTableDefault" {
+  yylval = NULL;
+  return TOK_RTTABLE_DEFAULT;
+}
+
 "Willingness" {
     yylval = NULL;
     return TOK_WILLINGNESS;
index 210c176..4a75bca 100644 (file)
@@ -55,113 +55,113 @@ static int delete_all_inet_gws(void);
 
 struct olsr_rtreq
 {
-       struct nlmsghdr         n;
-       struct rtmsg            r;
-       char                    buf[512];
+  struct nlmsghdr n;
+  struct rtmsg    r;
+  char            buf[512];
 };
 
 static void olsr_netlink_addreq(struct olsr_rtreq *req, int type, const void *data, int len)
 {
-       struct rtattr *rta = (struct rtattr*)(((char*)req) + NLMSG_ALIGN(req->n.nlmsg_len));
-       req->n.nlmsg_len = NLMSG_ALIGN(req->n.nlmsg_len) + RTA_LENGTH(len);
-       assert(req->n.nlmsg_len < sizeof(struct olsr_rtreq));
-       rta->rta_type = type;
-       rta->rta_len = RTA_LENGTH(len);
-       memcpy(RTA_DATA(rta), data, len);
+  struct rtattr *rta = (struct rtattr*)(((char*)req) + NLMSG_ALIGN(req->n.nlmsg_len));
+  req->n.nlmsg_len = NLMSG_ALIGN(req->n.nlmsg_len) + RTA_LENGTH(len);
+  assert(req->n.nlmsg_len < sizeof(struct olsr_rtreq));
+  rta->rta_type = type;
+  rta->rta_len = RTA_LENGTH(len);
+  memcpy(RTA_DATA(rta), data, len);
 }
 
 static int olsr_netlink_route(const struct rt_entry *rt, olsr_u8_t family, olsr_u8_t rttable, __u16 cmd)
 {
-       int ret = 0;
-       struct olsr_rtreq req;
-       struct iovec iov;
-       struct sockaddr_nl nladdr;
-       struct msghdr msg =
-       {
-               &nladdr,
-               sizeof(nladdr),
-               &iov,
-               1,
-               NULL,
-               0,
-               0
-       };
-       olsr_u32_t metric = FIBM_FLAT != olsr_cnf->fib_metric ? (RTM_NEWROUTE == cmd ?
-               rt->rt_best->rtp_metric.hops : rt->rt_metric.hops): RT_METRIC_DEFAULT;
-       const struct rt_nexthop* nexthop = (RTM_NEWROUTE == cmd) ?
-               &rt->rt_best->rtp_nexthop : &rt->rt_nexthop;
-
-       memset(&req, 0, sizeof(req));
-       req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct rtmsg));
-       req.n.nlmsg_flags = NLM_F_REQUEST|NLM_F_CREATE|NLM_F_EXCL|NLM_F_ACK;
-       req.n.nlmsg_type = cmd;
-       req.r.rtm_family = family;
-       req.r.rtm_table = rttable;
-       req.r.rtm_protocol = RTPROT_BOOT;
-       req.r.rtm_scope = RT_SCOPE_LINK;
-       req.r.rtm_type = RTN_UNICAST;
-       req.r.rtm_dst_len = rt->rt_dst.prefix_len;
-
-       if (AF_INET == family)
-       {
-               if (rt->rt_dst.prefix.v4.s_addr != nexthop->gateway.v4.s_addr)
-               {
-                       olsr_netlink_addreq(&req, RTA_GATEWAY, &nexthop->gateway.v4, sizeof(nexthop->gateway.v4));
-                       req.r.rtm_scope = RT_SCOPE_UNIVERSE;
-               }
-               olsr_netlink_addreq(&req, RTA_DST, &rt->rt_dst.prefix.v4, sizeof(rt->rt_dst.prefix.v4));
-       }
-       else
-       {
-               if (0 != memcmp(&rt->rt_dst.prefix.v6, &nexthop->gateway.v6, sizeof(nexthop->gateway.v6)))
-               {
-                       olsr_netlink_addreq(&req, RTA_GATEWAY, &nexthop->gateway.v6, sizeof(nexthop->gateway.v6));
-                       req.r.rtm_scope = RT_SCOPE_UNIVERSE;
-               }
-               olsr_netlink_addreq(&req, RTA_DST, &rt->rt_dst.prefix.v6, sizeof(rt->rt_dst.prefix.v6));
-       }
-       if (FIBM_APPROX != olsr_cnf->fib_metric || RTM_NEWROUTE == cmd)
-       {
-               olsr_netlink_addreq(&req, RTA_PRIORITY, &metric, sizeof(metric));
-       }
-       olsr_netlink_addreq(&req, RTA_OIF, &nexthop->iif_index, sizeof(nexthop->iif_index));
-       iov.iov_base = &req.n;
-       iov.iov_len = req.n.nlmsg_len;
-       memset(&nladdr, 0, sizeof(nladdr));
-       nladdr.nl_family = AF_NETLINK;
-       if (0 <= (ret = sendmsg(olsr_cnf->rtnl_s, &msg, 0)))
-       {
-               iov.iov_base = req.buf;
-               iov.iov_len = sizeof(req.buf);
-               if (0 < (ret = recvmsg(olsr_cnf->rtnl_s, &msg, 0)))
-               {
-                       struct nlmsghdr* h = (struct nlmsghdr*)req.buf;
-                       while (NLMSG_OK(h, (unsigned int)ret)) {
-                               if (NLMSG_DONE == h->nlmsg_type) break;
-                               if (NLMSG_ERROR == h->nlmsg_type)
-                               {
-                                       if (NLMSG_LENGTH(sizeof(struct nlmsgerr) <= h->nlmsg_len))
-                                       {
-                                               struct nlmsgerr *l_err = (struct nlmsgerr*)NLMSG_DATA(h);
-                                               errno = -l_err->error;
-                                               if (0 != errno) ret = -1;
-                                       }
-                                       break;
-                               }
-                               h = NLMSG_NEXT(h, ret);
-                       }
-               }
-               if (0 <= ret && olsr_cnf->ipc_connections > 0)
-               {
-                       ipc_route_send_rtentry(
-                               &rt->rt_dst.prefix,
-                               &nexthop->gateway,
-                               metric,
-                               RTM_NEWROUTE == cmd,
-                               if_ifwithindex_name(nexthop->iif_index));
-               }
-       }
-       return ret;
+  int ret = 0;
+  struct olsr_rtreq req;
+  struct iovec iov;
+  struct sockaddr_nl nladdr;
+  struct msghdr msg =
+  {
+    &nladdr,
+    sizeof(nladdr),
+    &iov,
+    1,
+    NULL,
+    0,
+    0
+  };
+  olsr_u32_t metric = FIBM_FLAT != olsr_cnf->fib_metric ? (RTM_NEWROUTE == cmd ?
+    rt->rt_best->rtp_metric.hops : rt->rt_metric.hops): RT_METRIC_DEFAULT;
+  const struct rt_nexthop* nexthop = (RTM_NEWROUTE == cmd) ?
+    &rt->rt_best->rtp_nexthop : &rt->rt_nexthop;
+
+  memset(&req, 0, sizeof(req));
+  req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct rtmsg));
+  req.n.nlmsg_flags = NLM_F_REQUEST|NLM_F_CREATE|NLM_F_EXCL|NLM_F_ACK;
+  req.n.nlmsg_type = cmd;
+  req.r.rtm_family = family;
+  req.r.rtm_table = rttable;
+  req.r.rtm_protocol = RTPROT_BOOT;
+  req.r.rtm_scope = RT_SCOPE_LINK;
+  req.r.rtm_type = RTN_UNICAST;
+  req.r.rtm_dst_len = rt->rt_dst.prefix_len;
+
+  if (AF_INET == family)
+  {
+    if (rt->rt_dst.prefix.v4.s_addr != nexthop->gateway.v4.s_addr)
+    {
+      olsr_netlink_addreq(&req, RTA_GATEWAY, &nexthop->gateway.v4, sizeof(nexthop->gateway.v4));
+      req.r.rtm_scope = RT_SCOPE_UNIVERSE;
+    }
+    olsr_netlink_addreq(&req, RTA_DST, &rt->rt_dst.prefix.v4, sizeof(rt->rt_dst.prefix.v4));
+  }
+  else
+  {
+    if (0 != memcmp(&rt->rt_dst.prefix.v6, &nexthop->gateway.v6, sizeof(nexthop->gateway.v6)))
+    {
+      olsr_netlink_addreq(&req, RTA_GATEWAY, &nexthop->gateway.v6, sizeof(nexthop->gateway.v6));
+      req.r.rtm_scope = RT_SCOPE_UNIVERSE;
+    }
+    olsr_netlink_addreq(&req, RTA_DST, &rt->rt_dst.prefix.v6, sizeof(rt->rt_dst.prefix.v6));
+  }
+  if (FIBM_APPROX != olsr_cnf->fib_metric || RTM_NEWROUTE == cmd)
+  {
+    olsr_netlink_addreq(&req, RTA_PRIORITY, &metric, sizeof(metric));
+  }
+  olsr_netlink_addreq(&req, RTA_OIF, &nexthop->iif_index, sizeof(nexthop->iif_index));
+  iov.iov_base = &req.n;
+  iov.iov_len = req.n.nlmsg_len;
+  memset(&nladdr, 0, sizeof(nladdr));
+  nladdr.nl_family = AF_NETLINK;
+  if (0 <= (ret = sendmsg(olsr_cnf->rtnl_s, &msg, 0)))
+  {
+    iov.iov_base = req.buf;
+    iov.iov_len = sizeof(req.buf);
+    if (0 < (ret = recvmsg(olsr_cnf->rtnl_s, &msg, 0)))
+    {
+      struct nlmsghdr* h = (struct nlmsghdr*)req.buf;
+      while (NLMSG_OK(h, (unsigned int)ret)) {
+        if (NLMSG_DONE == h->nlmsg_type) break;
+        if (NLMSG_ERROR == h->nlmsg_type)
+        {
+          if (NLMSG_LENGTH(sizeof(struct nlmsgerr) <= h->nlmsg_len))
+          {
+            struct nlmsgerr *l_err = (struct nlmsgerr*)NLMSG_DATA(h);
+            errno = -l_err->error;
+            if (0 != errno) ret = -1;
+          }
+          break;
+        }
+        h = NLMSG_NEXT(h, ret);
+      }
+    }
+    if (0 <= ret && olsr_cnf->ipc_connections > 0)
+    {
+      ipc_route_send_rtentry(
+        &rt->rt_dst.prefix,
+        &nexthop->gateway,
+        metric,
+        RTM_NEWROUTE == cmd,
+        if_ifwithindex_name(nexthop->iif_index));
+    }
+  }
+  return ret;
 }
 #endif /* LINUX_POLICY_ROUTING */
 
@@ -230,16 +230,19 @@ olsr_ioctl_add_route(const struct rt_entry *rt)
 
   return rslt;
 #else /* !LINUX_POLICY_ROUTING */
-       if (0 == rt->rt_dst.prefix_len && 253 > olsr_cnf->rttable)
-       {
-               /*
-                * Users start whining about not having internet with policy
-                * routing activated and no static default route in table 254.
-                * We maintain a fallback defroute in the default=253 table.
-                */
-               olsr_netlink_route(rt, AF_INET, 253, RTM_NEWROUTE);
-       }
-       return olsr_netlink_route(rt, AF_INET, olsr_cnf->rttable, RTM_NEWROUTE);
+  if (0 == olsr_cnf->rttable_default && 0 == rt->rt_dst.prefix_len && 253 > olsr_cnf->rttable)
+  {
+    /*
+     * Users start whining about not having internet with policy
+     * routing activated and no static default route in table 254.
+     * We maintain a fallback defroute in the default=253 table.
+     */
+    olsr_netlink_route(rt, AF_INET, 253, RTM_NEWROUTE);
+  }
+  if (0 == rt->rt_dst.prefix_len && olsr_cnf->rttable_default != 0)
+    return olsr_netlink_route(rt, AF_INET, olsr_cnf->rttable_default, RTM_NEWROUTE);
+  else
+    return olsr_netlink_route(rt, AF_INET, olsr_cnf->rttable, RTM_NEWROUTE);
 #endif /* LINUX_POLICY_ROUTING */
 }
 
@@ -289,7 +292,10 @@ olsr_ioctl_add_route6(const struct rt_entry *rt)
 
   return rslt;
 #else /* !LINUX_POLICY_ROUTING */
-       return olsr_netlink_route(rt, AF_INET6, olsr_cnf->rttable, RTM_NEWROUTE);
+  if (0 == rt->rt_dst.prefix_len && olsr_cnf->rttable_default != 0)
+    return olsr_netlink_route(rt, AF_INET6, olsr_cnf->rttable_default, RTM_NEWROUTE);
+  else
+    return olsr_netlink_route(rt, AF_INET6, olsr_cnf->rttable, RTM_NEWROUTE);
 #endif /* LINUX_POLICY_ROUTING */
 }
 
@@ -349,14 +355,17 @@ olsr_ioctl_del_route(const struct rt_entry *rt)
 
   return rslt;
 #else /* !LINUX_POLICY_ROUTING */
-       if (0 == rt->rt_dst.prefix_len && 253 > olsr_cnf->rttable)
-       {
-               /*
-                * Also remove the fallback default route
-                */
-               olsr_netlink_route(rt, AF_INET, 253, RTM_DELROUTE);
-       }
-       return olsr_netlink_route(rt, AF_INET, olsr_cnf->rttable, RTM_DELROUTE);
+  if (0 == olsr_cnf->rttable_default && 0 == rt->rt_dst.prefix_len && 253 > olsr_cnf->rttable)
+  {
+    /*
+     * Also remove the fallback default route
+     */
+    olsr_netlink_route(rt, AF_INET, 253, RTM_DELROUTE);
+  }
+  if (0 == rt->rt_dst.prefix_len && olsr_cnf->rttable_default != 0 )
+    return olsr_netlink_route(rt, AF_INET, olsr_cnf->rttable_default, RTM_DELROUTE);
+  else
+    return olsr_netlink_route(rt, AF_INET, olsr_cnf->rttable, RTM_DELROUTE);
 #endif /* LINUX_POLICY_ROUTING */
 }
 
@@ -400,7 +409,10 @@ olsr_ioctl_del_route6(const struct rt_entry *rt)
 
   return rslt;
 #else /* !LINUX_POLICY_ROUTING */
-       return olsr_netlink_route(rt, AF_INET6, olsr_cnf->rttable, RTM_DELROUTE);
+  if (0 == rt->rt_dst.prefix_len && olsr_cnf->rttable_default != 0)
+    return olsr_netlink_route(rt, AF_INET6, olsr_cnf->rttable_default, RTM_DELROUTE);
+  else
+    return olsr_netlink_route(rt, AF_INET6, olsr_cnf->rttable, RTM_DELROUTE);
 #endif /* LINUX_POLICY_ROUTING */
 }
 
index 8a02d37..54036b8 100644 (file)
@@ -201,6 +201,7 @@ struct olsrd_config
   olsr_bool                allow_no_interfaces;
   olsr_u16_t               tos;
   olsr_u8_t                rttable;
+  olsr_u8_t                rttable_default;
   olsr_u8_t                willingness;
   olsr_bool                willingness_auto;
   int                      ipc_connections;