bug-hurd
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 1/3] pfinet: Dump initial routing table at start up


From: Damien Zammit
Subject: [PATCH 1/3] pfinet: Dump initial routing table at start up
Date: Wed, 31 Aug 2022 14:37:23 +0000

---
 pfinet/iioctl-ops.c                       | 21 +++++++++++++++++++++
 pfinet/linux-src/net/ipv4/fib_hash.c      |  6 ------
 pfinet/linux-src/net/ipv4/fib_semantics.c |  4 ----
 pfinet/options.c                          |  8 ++++++++
 pfinet/pfinet.h                           |  4 +---
 5 files changed, 30 insertions(+), 13 deletions(-)

diff --git a/pfinet/iioctl-ops.c b/pfinet/iioctl-ops.c
index b128242bb..846bd8082 100644
--- a/pfinet/iioctl-ops.c
+++ b/pfinet/iioctl-ops.c
@@ -104,6 +104,7 @@ prepare_rt_req(struct rt_req *req, struct device *dev, 
in_addr_t dst, in_addr_t
   req->rtm.rtm_type = RTN_UNICAST;
   req->rtm.rtm_protocol = RTPROT_BOOT;
   req->rtm.rtm_dst_len = inet_mask_len(mask);
+  req->rtm.rtm_table = RT_TABLE_MAIN;

   return 0;
 }
@@ -234,6 +235,26 @@ delete_static_route(struct device *dev, in_addr_t dst, 
in_addr_t mask)
   return err;
 }

+/* Each route requires 128 bytes preallocated in a char buffer.
+   This will fetch up to count of them at offset start
+   and also consume one row for the header.
+   Returns number of routes dumped. If buf is NULL, give up.  */
+int
+get_routing_table(char *buf, int start, int count)
+{
+  struct fib_table *tb;
+
+  if (!buf)
+    return 0;
+
+  if ((tb = fib_get_table(RT_TABLE_MAIN)) == NULL)
+    return 0;
+
+  sprintf(buf, "%-127s\n", "Iface\tDestination\tGateway 
\tFlags\tRefCnt\tUse\tMetric\tMask\t\tMTU\tWindow\tIRTT");
+
+  return (*tb->tb_get_info)(tb, buf + 128, start, count);
+}
+
 error_t
 add_route (struct device *dev, const struct srtentry *r)
 {
diff --git a/pfinet/linux-src/net/ipv4/fib_hash.c 
b/pfinet/linux-src/net/ipv4/fib_hash.c
index 074a36876..d3e0d10a3 100644
--- a/pfinet/linux-src/net/ipv4/fib_hash.c
+++ b/pfinet/linux-src/net/ipv4/fib_hash.c
@@ -718,8 +718,6 @@ static int fn_hash_flush(struct fib_table *tb)
 }


-#ifdef CONFIG_PROC_FS
-
 static int fn_hash_get_info(struct fib_table *tb, char *buffer, int first, int 
count)
 {
        struct fn_hash *table = (struct fn_hash*)tb->tb_data;
@@ -758,8 +756,6 @@ static int fn_hash_get_info(struct fib_table *tb, char 
*buffer, int first, int c
        }
        return n;
 }
-#endif
-

 #ifdef CONFIG_RTNETLINK

@@ -877,9 +873,7 @@ __initfunc(struct fib_table * fib_hash_init(int id))
 #ifdef CONFIG_RTNETLINK
        tb->tb_dump = fn_hash_dump;
 #endif
-#ifdef CONFIG_PROC_FS
        tb->tb_get_info = fn_hash_get_info;
-#endif
        memset(tb->tb_data, 0, sizeof(struct fn_hash));
        return tb;
 }
diff --git a/pfinet/linux-src/net/ipv4/fib_semantics.c 
b/pfinet/linux-src/net/ipv4/fib_semantics.c
index ac7633170..7b12dfd71 100644
--- a/pfinet/linux-src/net/ipv4/fib_semantics.c
+++ b/pfinet/linux-src/net/ipv4/fib_semantics.c
@@ -950,8 +950,6 @@ void fib_select_multipath(const struct rt_key *key, struct 
fib_result *res)
 #endif


-#ifdef CONFIG_PROC_FS
-
 static unsigned fib_flag_trans(int type, int dead, u32 mask, struct fib_info 
*fi)
 {
        static unsigned type2flags[RTN_MAX+1] = {
@@ -987,5 +985,3 @@ void fib_node_get_info(int type, int dead, struct fib_info 
*fi, u32 prefix, u32
        memset(buffer+len, ' ', 127-len);
        buffer[127] = '\n';
 }
-
-#endif
diff --git a/pfinet/options.c b/pfinet/options.c
index 1e8c1c266..5039f4fbc 100644
--- a/pfinet/options.c
+++ b/pfinet/options.c
@@ -69,6 +69,9 @@ extern error_t delete_route (struct device *dev, struct 
srtentry *r);
 static struct rt6_info * ipv6_get_dflt_router (void);
 #endif

+#define MAX_INITIAL_ROUTES     32
+static char routes[(MAX_INITIAL_ROUTES + 1) * 128];
+
 
 /* Pfinet options.  Used for both startup and runtime.  */
 static const struct argp_option options[] =
@@ -568,6 +571,11 @@ parse_opt (int opt, char *arg, struct argp_state *state)
            }
        }

+        {
+          int n = get_routing_table(routes, 0, MAX_INITIAL_ROUTES);
+          printf("ROUTES: %d\n%s", n, routes);
+        }
+
       pthread_mutex_unlock (&global_lock);

       /* Fall through to free hook.  */
diff --git a/pfinet/pfinet.h b/pfinet/pfinet.h
index d08779bff..b4d5604dc 100644
--- a/pfinet/pfinet.h
+++ b/pfinet/pfinet.h
@@ -77,9 +77,7 @@ error_t make_sockaddr_port (struct socket *, int,
 void init_devices (void);
 void *net_bh_worker (void *);
 void init_time (void);
-void ip_rt_add (short, u_long, u_long, u_long, struct device *,
-               u_short, u_long);
-void ip_rt_del (u_long, struct device *);
+int get_routing_table(char *buf, int start, int count);
 struct sock;
 error_t tcp_tiocinq (struct sock *sk, mach_msg_type_number_t *amount);

--
2.34.1





reply via email to

[Prev in Thread] Current Thread [Next in Thread]