Skip to contentSkip to conversation

Initilize and populate age field

PATCH In review Varun Chandramohan 2 participants 5 messages Jul 26, 2007

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 3/4 Initilize and populate age field

The age field is filled with the current time at the time of creation of the route. When the routes are dumped
then the age value stored in the route structure is subtracted from the current time value and the difference is the age expressed in secs.

---
 net/ipv4/fib_hash.c      |    3 +++
 net/ipv4/fib_lookup.h    |    3 ++-
 net/ipv4/fib_semantics.c |   16 +++++++++++++---
 net/ipv4/fib_trie.c      |    1 +
 4 files changed, 19 insertions(+), 4 deletions(-)
net/ipv4/fib_hash.c +3 -0
index 07e843a..faa7364 100644
@@ -448,6 +448,7 @@ static int fn_hash_insert(struct fib_tab
 			fa->fa_info = fi;
 			fa->fa_type = cfg->fc_type;
 			fa->fa_scope = cfg->fc_scope;
+			fa->fa_age = 0;
 			state = fa->fa_state;
 			fa->fa_state &= ~FA_S_ACCESSED;
 			fib_hash_genid++;
@@ -507,6 +508,7 @@ static int fn_hash_insert(struct fib_tab
 	new_fa->fa_type = cfg->fc_type;
 	new_fa->fa_scope = cfg->fc_scope;
 	new_fa->fa_state = 0;
+	new_fa->fa_age = 0;
 
 	/*
 	 * Insert new entry to the list.
@@ -697,6 +699,7 @@ fn_hash_dump_bucket(struct sk_buff *skb,
 					  f->fn_key,
 					  fz->fz_order,
 					  fa->fa_tos,
+					  &fa->fa_age,
 					  fa->fa_info,
 					  NLM_F_MULTI) < 0) {
 				cb->args[4] = i;
net/ipv4/fib_lookup.h +2 -1
index eef9eec..c9145b5 100644
@@ -13,6 +13,7 @@ struct fib_alias {
 	u8			fa_type;
 	u8			fa_scope;
 	u8			fa_state;
+	time_t			fa_age;
 };
 
 #define FA_S_ACCESSED	0x01
@@ -27,7 +28,7 @@ extern struct fib_info *fib_create_info(
 extern int fib_nh_match(struct fib_config *cfg, struct fib_info *fi);
 extern int fib_dump_info(struct sk_buff *skb, u32 pid, u32 seq, int event,
 			 u32 tb_id, u8 type, u8 scope, __be32 dst,
-			 int dst_len, u8 tos, struct fib_info *fi,
+			 int dst_len, u8 tos, time_t *age, struct fib_info *fi,
 			 unsigned int);
 extern void rtmsg_fib(int event, __be32 key, struct fib_alias *fa,
 		      int dst_len, u32 tb_id, struct nl_info *info,
net/ipv4/fib_semantics.c +13 -3
index c434119..1822d92 100644
@@ -278,7 +278,8 @@ static inline size_t fib_nlmsg_size(stru
 			 + nla_total_size(4) /* RTA_TABLE */
 			 + nla_total_size(4) /* RTA_DST */
 			 + nla_total_size(4) /* RTA_PRIORITY */
-			 + nla_total_size(4); /* RTA_PREFSRC */
+			 + nla_total_size(4) /* RTA_PREFSRC */
+			 + nla_total_size(4); /*RTA_AGE*/
 
 	/* space for nested metrics */
 	payload += nla_total_size((RTAX_MAX * nla_total_size(4)));
@@ -313,7 +314,7 @@ void rtmsg_fib(int event, __be32 key, st
 
 	err = fib_dump_info(skb, info->pid, seq, event, tb_id,
 			    fa->fa_type, fa->fa_scope, key, dst_len,
-			    fa->fa_tos, fa->fa_info, nlm_flags);
+			    fa->fa_tos, &fa->fa_age, fa->fa_info, nlm_flags);
 	if (err < 0) {
 		/* -EMSGSIZE implies BUG in fib_nlmsg_size() */
 		WARN_ON(err == -EMSGSIZE);
@@ -940,11 +941,12 @@ __be32 __fib_res_prefsrc(struct fib_resu
 }
 
 int fib_dump_info(struct sk_buff *skb, u32 pid, u32 seq, int event,
-		  u32 tb_id, u8 type, u8 scope, __be32 dst, int dst_len, u8 tos,
+		  u32 tb_id, u8 type, u8 scope, __be32 dst, int dst_len, u8 tos, time_t *age,
 		  struct fib_info *fi, unsigned int flags)
 {
 	struct nlmsghdr *nlh;
 	struct rtmsg *rtm;
+	struct timeval tv;
 
 	nlh = nlmsg_put(skb, pid, seq, event, sizeof(*rtm), flags);
 	if (nlh == NULL)
@@ -985,6 +987,14 @@ int fib_dump_info(struct sk_buff *skb, u
 			NLA_PUT_U32(skb, RTA_FLOW, fi->fib_nh[0].nh_tclassid);
 #endif
 	}
+
+	do_gettimeofday(&tv);
+	if (!*age) {
+		*age = timeval_to_sec(&tv);
+		NLA_PUT_U32(skb, RTA_AGE, *age);
+	} else {
+		NLA_PUT_U32(skb, RTA_AGE, timeval_to_sec(&tv) - *age);
+	}
 #ifdef CONFIG_IP_ROUTE_MULTIPATH
 	if (fi->fib_nhs > 1) {
 		struct rtnexthop *rtnh;
net/ipv4/fib_trie.c +1 -0
index 30e332a..be2d1d6 100644
@@ -1884,6 +1884,7 @@ static int fn_trie_dump_fa(t_key key, in
 				  xkey,
 				  plen,
 				  fa->fa_tos,
+				  &fa->fa_age,
 				  fa->fa_info, 0) < 0) {
 			cb->args[4] = i;
 			return -1;
Signature · 1 line
1.4.3.4
#1 lore raw
Quoted 65 lines · Varun Chandramohan

The age field is filled with the current time at the time of creation of the route. When the routes are dumped
then the age value stored in the route structure is subtracted from the current time value and the difference is the age expressed in secs.

---
 net/ipv4/fib_hash.c      |    3 +++
 net/ipv4/fib_lookup.h    |    3 ++-
 net/ipv4/fib_semantics.c |   16 +++++++++++++---
 net/ipv4/fib_trie.c      |    1 +
 4 files changed, 19 insertions(+), 4 deletions(-)
net/ipv4/fib_hash.c +3 -0
index 07e843a..faa7364 100644
@@ -448,6 +448,7 @@ static int fn_hash_insert(struct fib_tab
 			fa->fa_info = fi;
 			fa->fa_type = cfg->fc_type;
 			fa->fa_scope = cfg->fc_scope;
+			fa->fa_age = 0;
 			state = fa->fa_state;
 			fa->fa_state &= ~FA_S_ACCESSED;
 			fib_hash_genid++;
@@ -507,6 +508,7 @@ static int fn_hash_insert(struct fib_tab
 	new_fa->fa_type = cfg->fc_type;
 	new_fa->fa_scope = cfg->fc_scope;
 	new_fa->fa_state = 0;
+	new_fa->fa_age = 0;
 
 	/*
 	 * Insert new entry to the list.
@@ -697,6 +699,7 @@ fn_hash_dump_bucket(struct sk_buff *skb,
 					  f->fn_key,
 					  fz->fz_order,
 					  fa->fa_tos,
+					  &fa->fa_age,
 					  fa->fa_info,
 					  NLM_F_MULTI) < 0) {
 				cb->args[4] = i;
net/ipv4/fib_lookup.h +2 -1
index eef9eec..c9145b5 100644
@@ -13,6 +13,7 @@ struct fib_alias {
 	u8			fa_type;
 	u8			fa_scope;
 	u8			fa_state;
+	time_t			fa_age;
 };
 
 #define FA_S_ACCESSED	0x01
@@ -27,7 +28,7 @@ extern struct fib_info *fib_create_info(
 extern int fib_nh_match(struct fib_config *cfg, struct fib_info *fi);
 extern int fib_dump_info(struct sk_buff *skb, u32 pid, u32 seq, int event,
 			 u32 tb_id, u8 type, u8 scope, __be32 dst,
-			 int dst_len, u8 tos, struct fib_info *fi,
+			 int dst_len, u8 tos, time_t *age, struct fib_info *fi,
 			 unsigned int);
 extern void rtmsg_fib(int event, __be32 key, struct fib_alias *fa,
 		      int dst_len, u32 tb_id, struct nl_info *info,
net/ipv4/fib_semantics.c +0 -0
index c434119..1822d92 100644

net/ipv4/fib_semantics.c static inline size_t fib_nlmsg_size(stru · line 282

Quoted 6 lines
net/ipv4/fib_semantics.c +2 -1
@@ -278,7 +278,8 @@ static inline size_t fib_nlmsg_size(stru
 			 + nla_total_size(4) /* RTA_TABLE */
 			 + nla_total_size(4) /* RTA_DST */
 			 + nla_total_size(4) /* RTA_PRIORITY */
-			 + nla_total_size(4); /* RTA_PREFSRC */
+			 + nla_total_size(4) /* RTA_PREFSRC */
+			 + nla_total_size(4); /*RTA_AGE*/

Not clear to me what happens on platforms where sizeof(time_t) is 8

Quoted 27 lines
net/ipv4/fib_semantics.c +3 -2
 	/* space for nested metrics */
 	payload += nla_total_size((RTAX_MAX * nla_total_size(4)));
@@ -313,7 +314,7 @@ void rtmsg_fib(int event, __be32 key, st
 
 	err = fib_dump_info(skb, info->pid, seq, event, tb_id,
 			    fa->fa_type, fa->fa_scope, key, dst_len,
-			    fa->fa_tos, fa->fa_info, nlm_flags);
+			    fa->fa_tos, &fa->fa_age, fa->fa_info, nlm_flags);
 	if (err < 0) {
 		/* -EMSGSIZE implies BUG in fib_nlmsg_size() */
 		WARN_ON(err == -EMSGSIZE);
@@ -940,11 +941,12 @@ __be32 __fib_res_prefsrc(struct fib_resu
 }
 
 int fib_dump_info(struct sk_buff *skb, u32 pid, u32 seq, int event,
-		  u32 tb_id, u8 type, u8 scope, __be32 dst, int dst_len, u8 tos,
+		  u32 tb_id, u8 type, u8 scope, __be32 dst, int dst_len, u8 tos, time_t *age,
 		  struct fib_info *fi, unsigned int flags)
 {
 	struct nlmsghdr *nlh;
 	struct rtmsg *rtm;
+	struct timeval tv;
 
 	nlh = nlmsg_put(skb, pid, seq, event, sizeof(*rtm), flags);
 	if (nlh == NULL)

net/ipv4/fib_semantics.c int fib_dump_info(struct sk_buff *skb, u · line 994

Quoted 8 lines
net/ipv4/fib_semantics.c +5 -0
@@ -985,6 +987,14 @@ int fib_dump_info(struct sk_buff *skb, u
 			NLA_PUT_U32(skb, RTA_FLOW, fi->fib_nh[0].nh_tclassid);
 #endif
 	}
+
+	do_gettimeofday(&tv);
+	if (!*age) {
+		*age = timeval_to_sec(&tv);
+		NLA_PUT_U32(skb, RTA_AGE, *age);

here, what happens if sizeof(time_t) is not 4 ?

Quoted 18 lines
net/ipv4/fib_semantics.c +3 -0
+	} else {
+		NLA_PUT_U32(skb, RTA_AGE, timeval_to_sec(&tv) - *age);
+	}
 #ifdef CONFIG_IP_ROUTE_MULTIPATH
 	if (fi->fib_nhs > 1) {
 		struct rtnexthop *rtnh;
net/ipv4/fib_trie.c +1 -0
index 30e332a..be2d1d6 100644
@@ -1884,6 +1884,7 @@ static int fn_trie_dump_fa(t_key key, in
 				  xkey,
 				  plen,
 				  fa->fa_tos,
+				  &fa->fa_age,
 				  fa->fa_info, 0) < 0) {
 			cb->args[4] = i;
 			return -1;
#2 lore raw
Quoted 69 lines · Eric Dumazet
Quoted 68 lines · Varun Chandramohan

The age field is filled with the current time at the time of creation of the route. When the routes are dumped
then the age value stored in the route structure is subtracted from the current time value and the difference is the age expressed in secs.

---
 net/ipv4/fib_hash.c      |    3 +++
 net/ipv4/fib_lookup.h    |    3 ++-
 net/ipv4/fib_semantics.c |   16 +++++++++++++---
 net/ipv4/fib_trie.c      |    1 +
 4 files changed, 19 insertions(+), 4 deletions(-)
net/ipv4/fib_hash.c +3 -0
index 07e843a..faa7364 100644
@@ -448,6 +448,7 @@ static int fn_hash_insert(struct fib_tab
             fa->fa_info = fi;
             fa->fa_type = cfg->fc_type;
             fa->fa_scope = cfg->fc_scope;
+            fa->fa_age = 0;
             state = fa->fa_state;
             fa->fa_state &= ~FA_S_ACCESSED;
             fib_hash_genid++;
@@ -507,6 +508,7 @@ static int fn_hash_insert(struct fib_tab
     new_fa->fa_type = cfg->fc_type;
     new_fa->fa_scope = cfg->fc_scope;
     new_fa->fa_state = 0;
+    new_fa->fa_age = 0;
 
     /*
      * Insert new entry to the list.
@@ -697,6 +699,7 @@ fn_hash_dump_bucket(struct sk_buff *skb,
                       f->fn_key,
                       fz->fz_order,
                       fa->fa_tos,
+                      &fa->fa_age,
                       fa->fa_info,
                       NLM_F_MULTI) < 0) {
                 cb->args[4] = i;
net/ipv4/fib_lookup.h +2 -1
index eef9eec..c9145b5 100644
@@ -13,6 +13,7 @@ struct fib_alias {
     u8            fa_type;
     u8            fa_scope;
     u8            fa_state;
+    time_t            fa_age;
 };
 
 #define FA_S_ACCESSED    0x01
@@ -27,7 +28,7 @@ extern struct fib_info *fib_create_info(
 extern int fib_nh_match(struct fib_config *cfg, struct fib_info *fi);
 extern int fib_dump_info(struct sk_buff *skb, u32 pid, u32 seq, int
 event,
              u32 tb_id, u8 type, u8 scope, __be32 dst,
-             int dst_len, u8 tos, struct fib_info *fi,
+             int dst_len, u8 tos, time_t *age, struct fib_info *fi,
              unsigned int);
 extern void rtmsg_fib(int event, __be32 key, struct fib_alias *fa,

int dst_len, u32 tb_id, struct nl_info *info,

net/ipv4/fib_semantics.c +0 -0
index c434119..1822d92 100644
@@ -278,7 +278,8 @@ static inline size_t fib_nlmsg_size(stru
Quoted 9 lines

net/ipv4/fib_semantics.c static inline size_t fib_nlmsg_size(stru · line 282

Quoted 6 lines
net/ipv4/fib_semantics.c +2 -1
              + nla_total_size(4) /* RTA_TABLE */
              + nla_total_size(4) /* RTA_DST */
              + nla_total_size(4) /* RTA_PRIORITY */
-             + nla_total_size(4); /* RTA_PREFSRC */
+             + nla_total_size(4) /* RTA_PREFSRC */
+             + nla_total_size(4); /*RTA_AGE*/

Not clear to me what happens on platforms where sizeof(time_t) is 8

I was aware of this issue, but the reason we decided to go with 4 is that netlink is defined for use across a network. Since the size of time_t varies in different architecture, it would mean that a system with size 4 may not be able to talk to system with size 8. So i made it constant. So in the above case we round off to 4.

Quoted 27 lines
Quoted 27 lines
net/ipv4/fib_semantics.c +3 -2
     /* space for nested metrics */
     payload += nla_total_size((RTAX_MAX * nla_total_size(4)));
@@ -313,7 +314,7 @@ void rtmsg_fib(int event, __be32 key, st
 
     err = fib_dump_info(skb, info->pid, seq, event, tb_id,
                 fa->fa_type, fa->fa_scope, key, dst_len,
-                fa->fa_tos, fa->fa_info, nlm_flags);
+                fa->fa_tos, &fa->fa_age, fa->fa_info, nlm_flags);
     if (err < 0) {
         /* -EMSGSIZE implies BUG in fib_nlmsg_size() */
         WARN_ON(err == -EMSGSIZE);
@@ -940,11 +941,12 @@ __be32 __fib_res_prefsrc(struct fib_resu
 }
 
 int fib_dump_info(struct sk_buff *skb, u32 pid, u32 seq, int event,
-          u32 tb_id, u8 type, u8 scope, __be32 dst, int dst_len, u8
 tos,
+          u32 tb_id, u8 type, u8 scope, __be32 dst, int dst_len, u8
 tos, time_t *age,
           struct fib_info *fi, unsigned int flags)
 {
     struct nlmsghdr *nlh;
     struct rtmsg *rtm;
+    struct timeval tv;
 
Quoted 14 lines

net/ipv4/fib_semantics.c int fib_dump_info(struct sk_buff *skb, u · line 994

Quoted 11 lines
     nlh = nlmsg_put(skb, pid, seq, event, sizeof(*rtm), flags);
     if (nlh == NULL)
net/ipv4/fib_semantics.c +5 -0
@@ -985,6 +987,14 @@ int fib_dump_info(struct sk_buff *skb, u
             NLA_PUT_U32(skb, RTA_FLOW, fi->fib_nh[0].nh_tclassid);
 #endif
     }
+
+    do_gettimeofday(&tv);
+    if (!*age) {
+        *age = timeval_to_sec(&tv);
+        NLA_PUT_U32(skb, RTA_AGE, *age);

here, what happens if sizeof(time_t) is not 4 ?

Same case as above :-) comments?

Quoted 23 lines
Quoted 11 lines
net/ipv4/fib_semantics.c +3 -0
+    } else {
+        NLA_PUT_U32(skb, RTA_AGE, timeval_to_sec(&tv) - *age);
+    }
 #ifdef CONFIG_IP_ROUTE_MULTIPATH
     if (fi->fib_nhs > 1) {
         struct rtnexthop *rtnh;
net/ipv4/fib_trie.c +0 -0
index 30e332a..be2d1d6 100644

net/ipv4/fib_trie.c static int fn_trie_dump_fa(t_key key, in · line 1890

Quoted 7 lines
net/ipv4/fib_trie.c +1 -0
@@ -1884,6 +1884,7 @@ static int fn_trie_dump_fa(t_key key, in
                   xkey,
                   plen,
                   fa->fa_tos,
+                  &fa->fa_age,
                   fa->fa_info, 0) < 0) {
             cb->args[4] = i;
             return -1;

-
To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#3 lore raw
Quoted 13 lines · Varun Chandramohan
Quoted 12 lines · Eric Dumazet
Quoted 11 lines · Varun Chandramohan

The age field is filled with the current time at the time of creation of the route. When the routes are dumped
then the age value stored in the route structure is subtracted from the current time value and the difference is the age expressed in secs.

     }
net/ipv4/fib_semantics.c +5 -0
+
+    do_gettimeofday(&tv);
+    if (!*age) {
+        *age = timeval_to_sec(&tv);
+        NLA_PUT_U32(skb, RTA_AGE, *age);
Quoted 3 lines
Quoted 2 lines

here, what happens if sizeof(time_t) is not 4 ?

Same case as above :-) comments?

So you are confident it (truncation from 8 to 4 bytes) works well on Big endian arches as well as Little endian arches ? :-)

#4 lore raw
Quoted 15 lines · Eric Dumazet
Quoted 14 lines · Varun Chandramohan
Quoted 13 lines · Eric Dumazet
Quoted 12 lines · Varun Chandramohan

The age field is filled with the current time at the time of creation of the route. When the routes are dumped
then the age value stored in the route structure is subtracted from the current time value and the difference is the age expressed in secs.

     }
net/ipv4/fib_semantics.c +5 -0
+
+    do_gettimeofday(&tv);
+    if (!*age) {
+        *age = timeval_to_sec(&tv);
+        NLA_PUT_U32(skb, RTA_AGE, *age);
Quoted 7 lines
Quoted 3 lines
Quoted 2 lines

here, what happens if sizeof(time_t) is not 4 ?

Same case as above :-) comments?

So you are confident it (truncation from 8 to 4 bytes) works well on Big endian arches as well as Little endian arches ? :-)

I suppose so. But i must admit i have'nt tested it on Big endian arch though!!!

Quoted 5 lines

-
To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html