Re: [PATCH 2/4] [IPV4]: Convert IPv4 devconf to an array

2007-06-04 Thread David Miller
From: Herbert Xu <[EMAIL PROTECTED]>
Date: Tue, 05 Jun 2007 16:31:02 +1000

> [IPV4]: Convert IPv4 devconf to an array
> 
> This patch converts the ipv4_devconf config members (everything except
> sysctl) to an array.  This allows easier manipulation which will be
> needed later on to provide better management of default config values.
> 
> Signed-off-by: Herbert Xu <[EMAIL PROTECTED]>

Applied, thanks.
-
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


[PATCH 2/4] [IPV4]: Convert IPv4 devconf to an array

2007-06-04 Thread Herbert Xu
[IPV4]: Convert IPv4 devconf to an array

This patch converts the ipv4_devconf config members (everything except
sysctl) to an array.  This allows easier manipulation which will be
needed later on to provide better management of default config values.

Signed-off-by: Herbert Xu <[EMAIL PROTECTED]>
---

 drivers/infiniband/hw/amso1100/c2.c |2 
 include/linux/inetdevice.h  |   94 +++-
 net/ipv4/arp.c  |   11 -
 net/ipv4/devinet.c  |  264 ++--
 net/ipv4/igmp.c |   18 +-
 net/ipv4/ipmr.c |   12 -
 net/ipv4/proc.c |2 
 net/ipv4/route.c|   14 -
 net/ipv4/sysctl_net_ipv4.c  |6 
 9 files changed, 163 insertions(+), 260 deletions(-)

diff --git a/drivers/infiniband/hw/amso1100/c2.c 
b/drivers/infiniband/hw/amso1100/c2.c
--- a/drivers/infiniband/hw/amso1100/c2.c
+++ b/drivers/infiniband/hw/amso1100/c2.c
@@ -672,7 +672,7 @@ static int c2_up(struct net_device *netd
 * rdma interface.
 */
in_dev = in_dev_get(netdev);
-   in_dev->cnf.arp_ignore = 1;
+   IN_DEV_CONF_SET(in_dev, ARP_IGNORE, 1);
in_dev_put(in_dev);
 
return 0;
diff --git a/include/linux/inetdevice.h b/include/linux/inetdevice.h
--- a/include/linux/inetdevice.h
+++ b/include/linux/inetdevice.h
@@ -10,28 +10,8 @@
 
 struct ipv4_devconf
 {
-   int accept_redirects;
-   int send_redirects;
-   int secure_redirects;
-   int shared_media;
-   int accept_source_route;
-   int rp_filter;
-   int proxy_arp;
-   int bootp_relay;
-   int log_martians;
-   int forwarding;
-   int mc_forwarding;
-   int tag;
-   int arp_filter;
-   int arp_announce;
-   int arp_ignore;
-   int arp_accept;
-   int medium_id;
-   int no_xfrm;
-   int no_policy;
-   int force_igmp_version;
-   int promote_secondaries;
void*sysctl;
+   int data[__NET_IPV4_CONF_MAX - 1];
 };
 
 extern struct ipv4_devconf ipv4_devconf;
@@ -60,30 +40,64 @@ struct in_device
struct rcu_head rcu_head;
 };
 
-#define IN_DEV_FORWARD(in_dev) ((in_dev)->cnf.forwarding)
-#define IN_DEV_MFORWARD(in_dev)(ipv4_devconf.mc_forwarding && 
(in_dev)->cnf.mc_forwarding)
-#define IN_DEV_RPFILTER(in_dev)(ipv4_devconf.rp_filter && 
(in_dev)->cnf.rp_filter)
-#define IN_DEV_SOURCE_ROUTE(in_dev)(ipv4_devconf.accept_source_route && 
(in_dev)->cnf.accept_source_route)
-#define IN_DEV_BOOTP_RELAY(in_dev) (ipv4_devconf.bootp_relay && 
(in_dev)->cnf.bootp_relay)
-
-#define IN_DEV_LOG_MARTIANS(in_dev)(ipv4_devconf.log_martians || 
(in_dev)->cnf.log_martians)
-#define IN_DEV_PROXY_ARP(in_dev)   (ipv4_devconf.proxy_arp || 
(in_dev)->cnf.proxy_arp)
-#define IN_DEV_SHARED_MEDIA(in_dev)(ipv4_devconf.shared_media || 
(in_dev)->cnf.shared_media)
-#define IN_DEV_TX_REDIRECTS(in_dev)(ipv4_devconf.send_redirects || 
(in_dev)->cnf.send_redirects)
-#define IN_DEV_SEC_REDIRECTS(in_dev)   (ipv4_devconf.secure_redirects || 
(in_dev)->cnf.secure_redirects)
-#define IN_DEV_IDTAG(in_dev)   ((in_dev)->cnf.tag)
-#define IN_DEV_MEDIUM_ID(in_dev)   ((in_dev)->cnf.medium_id)
-#define IN_DEV_PROMOTE_SECONDARIES(in_dev) 
(ipv4_devconf.promote_secondaries || (in_dev)->cnf.promote_secondaries)
+#define IPV4_DEVCONF(cnf, attr) ((cnf).data[NET_IPV4_CONF_ ## attr - 1])
+#define IPV4_DEVCONF_ALL(attr) IPV4_DEVCONF(ipv4_devconf, attr)
+
+static inline int ipv4_devconf_get(struct in_device *in_dev, int index)
+{
+   index--;
+   return in_dev->cnf.data[index];
+}
+
+static inline void ipv4_devconf_set(struct in_device *in_dev, int index,
+   int val)
+{
+   index--;
+   in_dev->cnf.data[index] = val;
+}
+
+#define IN_DEV_CONF_GET(in_dev, attr) \
+   ipv4_devconf_get((in_dev), NET_IPV4_CONF_ ## attr)
+#define IN_DEV_CONF_SET(in_dev, attr, val) \
+   ipv4_devconf_set((in_dev), NET_IPV4_CONF_ ## attr, (val))
+
+#define IN_DEV_ANDCONF(in_dev, attr) \
+   (IPV4_DEVCONF_ALL(attr) && IN_DEV_CONF_GET((in_dev), attr))
+#define IN_DEV_ORCONF(in_dev, attr) \
+   (IPV4_DEVCONF_ALL(attr) || IN_DEV_CONF_GET((in_dev), attr))
+#define IN_DEV_MAXCONF(in_dev, attr) \
+   (max(IPV4_DEVCONF_ALL(attr), IN_DEV_CONF_GET((in_dev), attr)))
+
+#define IN_DEV_FORWARD(in_dev) IN_DEV_CONF_GET((in_dev), FORWARDING)
+#define IN_DEV_MFORWARD(in_dev)
(IPV4_DEVCONF_ALL(MC_FORWARDING) && \
+IPV4_DEVCONF((in_dev)->cnf, \
+ MC_FORWARDING))
+#define IN_DEV_RPFILTER(in_dev)IN_DEV_ANDCONF((in_dev), 
RP_FILTER)
+#define IN_DEV_SOURCE_ROUTE(in_dev)IN_DEV_ANDCONF((in_dev), \
+  

Re: [2/4] [IPV4]: Convert IPv4 devconf to an array

2007-06-04 Thread Herbert Xu
On Mon, Jun 04, 2007 at 11:17:54PM -0700, David Miller wrote:
> 
> These array indexes are off by one.

Good catch.  I'll repost this.

> This is the danger in using this "x-1" indexing style.
> Such a mistake is way too easy to make.

Yes, unfortunately the NET_IPV4_* constants are exposed to user-space
so I can't easily change them.  Inventing a new set of constants didn't
seem to be worthwhile.  The other option would be to keep the symbolic
names with a union or explicit pointer calculations for the bitmap, but
this seemed to me to be the least ugly of all the alternatives.

If it's any consolation, this should be the only spot where we use
these constants directly.

Cheers,
-- 
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmV>HI~} <[EMAIL PROTECTED]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
-
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


Re: [2/4] [IPV4]: Convert IPv4 devconf to an array

2007-06-04 Thread David Miller
From: Herbert Xu <[EMAIL PROTECTED]>
Date: Sat, 2 Jun 2007 20:02:52 +1000

> @@ -64,20 +64,26 @@
>  #include 
>  
>  struct ipv4_devconf ipv4_devconf = {
> - .accept_redirects = 1,
> - .send_redirects =  1,
> - .secure_redirects = 1,
> - .shared_media =   1,
> + .data = {
> + [NET_IPV4_CONF_ACCEPT_REDIRECTS] = 1,
> + [NET_IPV4_CONF_SEND_REDIRECTS] = 1,
> + [NET_IPV4_CONF_SECURE_REDIRECTS] = 1,
> + [NET_IPV4_CONF_SHARED_MEDIA] = 1,
> + },
>  };

These array indexes are off by one.

This is the danger in using this "x-1" indexing style.
Such a mistake is way too easy to make.
-
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


Re: [2/4] [IPV4]: Convert IPv4 devconf to an array

2007-06-02 Thread jamal
On Sat, 2007-02-06 at 20:02 +1000, Herbert Xu wrote:
> [IPV4]: Convert IPv4 devconf to an array
> 
> This patch converts the ipv4_devconf config members (everything except
> sysctl) to an array.  This allows easier manipulation which will be
> needed later on to provide better management of default config values.
> 

Nice.
What be even nicer (wink, wink) is to be able to generate events when
these values change. Thomas and I once had long discussions on that
topic. It could be as primitive as a select()/poll() kicking in
when /proc/sys/net/ipv4/conf/default changes.
BTW, the fact select() doesnt kick at all (been a while since i last
tried) is something that seems to be a bug.

cheers,
jamal

-
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


[2/4] [IPV4]: Convert IPv4 devconf to an array

2007-06-02 Thread Herbert Xu
[IPV4]: Convert IPv4 devconf to an array

This patch converts the ipv4_devconf config members (everything except
sysctl) to an array.  This allows easier manipulation which will be
needed later on to provide better management of default config values.

Signed-off-by: Herbert Xu <[EMAIL PROTECTED]>
-- 
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmV>HI~} <[EMAIL PROTECTED]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
--
diff --git a/drivers/infiniband/hw/amso1100/c2.c 
b/drivers/infiniband/hw/amso1100/c2.c
--- a/drivers/infiniband/hw/amso1100/c2.c
+++ b/drivers/infiniband/hw/amso1100/c2.c
@@ -672,7 +672,7 @@ static int c2_up(struct net_device *netd
 * rdma interface.
 */
in_dev = in_dev_get(netdev);
-   in_dev->cnf.arp_ignore = 1;
+   IN_DEV_CONF_SET(in_dev, ARP_IGNORE, 1);
in_dev_put(in_dev);
 
return 0;
diff --git a/include/linux/inetdevice.h b/include/linux/inetdevice.h
--- a/include/linux/inetdevice.h
+++ b/include/linux/inetdevice.h
@@ -10,28 +10,8 @@
 
 struct ipv4_devconf
 {
-   int accept_redirects;
-   int send_redirects;
-   int secure_redirects;
-   int shared_media;
-   int accept_source_route;
-   int rp_filter;
-   int proxy_arp;
-   int bootp_relay;
-   int log_martians;
-   int forwarding;
-   int mc_forwarding;
-   int tag;
-   int arp_filter;
-   int arp_announce;
-   int arp_ignore;
-   int arp_accept;
-   int medium_id;
-   int no_xfrm;
-   int no_policy;
-   int force_igmp_version;
-   int promote_secondaries;
void*sysctl;
+   int data[__NET_IPV4_CONF_MAX - 1];
 };
 
 extern struct ipv4_devconf ipv4_devconf;
@@ -60,30 +40,64 @@ struct in_device
struct rcu_head rcu_head;
 };
 
-#define IN_DEV_FORWARD(in_dev) ((in_dev)->cnf.forwarding)
-#define IN_DEV_MFORWARD(in_dev)(ipv4_devconf.mc_forwarding && 
(in_dev)->cnf.mc_forwarding)
-#define IN_DEV_RPFILTER(in_dev)(ipv4_devconf.rp_filter && 
(in_dev)->cnf.rp_filter)
-#define IN_DEV_SOURCE_ROUTE(in_dev)(ipv4_devconf.accept_source_route && 
(in_dev)->cnf.accept_source_route)
-#define IN_DEV_BOOTP_RELAY(in_dev) (ipv4_devconf.bootp_relay && 
(in_dev)->cnf.bootp_relay)
-
-#define IN_DEV_LOG_MARTIANS(in_dev)(ipv4_devconf.log_martians || 
(in_dev)->cnf.log_martians)
-#define IN_DEV_PROXY_ARP(in_dev)   (ipv4_devconf.proxy_arp || 
(in_dev)->cnf.proxy_arp)
-#define IN_DEV_SHARED_MEDIA(in_dev)(ipv4_devconf.shared_media || 
(in_dev)->cnf.shared_media)
-#define IN_DEV_TX_REDIRECTS(in_dev)(ipv4_devconf.send_redirects || 
(in_dev)->cnf.send_redirects)
-#define IN_DEV_SEC_REDIRECTS(in_dev)   (ipv4_devconf.secure_redirects || 
(in_dev)->cnf.secure_redirects)
-#define IN_DEV_IDTAG(in_dev)   ((in_dev)->cnf.tag)
-#define IN_DEV_MEDIUM_ID(in_dev)   ((in_dev)->cnf.medium_id)
-#define IN_DEV_PROMOTE_SECONDARIES(in_dev) 
(ipv4_devconf.promote_secondaries || (in_dev)->cnf.promote_secondaries)
+#define IPV4_DEVCONF(cnf, attr) ((cnf).data[NET_IPV4_CONF_ ## attr - 1])
+#define IPV4_DEVCONF_ALL(attr) IPV4_DEVCONF(ipv4_devconf, attr)
+
+static inline int ipv4_devconf_get(struct in_device *in_dev, int index)
+{
+   index--;
+   return in_dev->cnf.data[index];
+}
+
+static inline void ipv4_devconf_set(struct in_device *in_dev, int index,
+   int val)
+{
+   index--;
+   in_dev->cnf.data[index] = val;
+}
+
+#define IN_DEV_CONF_GET(in_dev, attr) \
+   ipv4_devconf_get((in_dev), NET_IPV4_CONF_ ## attr)
+#define IN_DEV_CONF_SET(in_dev, attr, val) \
+   ipv4_devconf_set((in_dev), NET_IPV4_CONF_ ## attr, (val))
+
+#define IN_DEV_ANDCONF(in_dev, attr) \
+   (IPV4_DEVCONF_ALL(attr) && IN_DEV_CONF_GET((in_dev), attr))
+#define IN_DEV_ORCONF(in_dev, attr) \
+   (IPV4_DEVCONF_ALL(attr) || IN_DEV_CONF_GET((in_dev), attr))
+#define IN_DEV_MAXCONF(in_dev, attr) \
+   (max(IPV4_DEVCONF_ALL(attr), IN_DEV_CONF_GET((in_dev), attr)))
+
+#define IN_DEV_FORWARD(in_dev) IN_DEV_CONF_GET((in_dev), FORWARDING)
+#define IN_DEV_MFORWARD(in_dev)
(IPV4_DEVCONF_ALL(MC_FORWARDING) && \
+IPV4_DEVCONF((in_dev)->cnf, \
+ MC_FORWARDING))
+#define IN_DEV_RPFILTER(in_dev)IN_DEV_ANDCONF((in_dev), 
RP_FILTER)
+#define IN_DEV_SOURCE_ROUTE(in_dev)IN_DEV_ANDCONF((in_dev), \
+  ACCEPT_SOURCE_ROUTE)
+#define IN_DEV_BOOTP_RELAY(in_dev) IN_DEV_ANDCONF((in_dev), BOOTP_RELAY)
+
+#define IN_DEV_LOG_MARTIANS(in_dev)IN_DEV_ORCONF((in_dev), LOG_MARTIANS)
+#define IN_DEV_PROXY_ARP(in_dev)   IN_DEV_ORCONF((in_dev), PROXY_ARP)
+#define IN_DEV_SHARED_MEDIA(in_dev)