Skip to contentSkip to conversation

Make xfrm subsystem optional

PATCH In review Andi Kleen 4 participants 12 messages Jun 14, 2003 – Jun 15, 2003

Subsystems (5)
lore
Share & tools
lore

Andi Kleen

author
#0 lore raw

PATCH 1/1 Make xfrm subsystem optional

This patches only compiles the xfrm subsystem in when any of the options using it are selected. This shrinks the text segment on an amd64 kernel by ~32k, data by ~6k, bss by ~33k, overall ~72K memory saved.

-Andi

Index: linux/include/net/dst.h
===================================================================
RCS file: /home/cvs/linux-2.5/include/net/dst.h,v
retrieving revision 1.11

include/net/dst.h +8 -0
diff -u -r1.11 dst.h
@@ -247,8 +247,16 @@
 extern void		dst_init(void);
 
 struct flowi;
+#ifndef CONFIG_XFRM
+static inline int xfrm_lookup(struct dst_entry **dst_p, struct flowi *fl,
+		       struct sock *sk, int flags)
+{
+	return 0;
+} 
+#else
 extern int xfrm_lookup(struct dst_entry **dst_p, struct flowi *fl,
 		       struct sock *sk, int flags);
+#endif
 #endif
 
 #endif /* _NET_DST_H */

Index: linux/include/net/xfrm.h
===================================================================
RCS file: /home/cvs/linux-2.5/include/net/xfrm.h,v retrieving revision 1.34

include/net/xfrm.h +41 -2

73 lines not on this page · raw message

Index: linux/net/Kconfig
===================================================================
RCS file: /home/cvs/linux-2.5/net/Kconfig,v
retrieving revision 1.14

net/Kconfig +1 -0
diff -u -r1.14 Kconfig
@@ -143,6 +143,7 @@
 
 config NET_KEY
 	tristate "PF_KEY sockets"
+	select XFRM
 	---help---
 	  PF_KEYv2 socket family, compatible to KAME ones.
 	  They are required if you are going to use IPsec tools ported

Index: linux/net/netsyms.c
===================================================================
RCS file: /home/cvs/linux-2.5/net/netsyms.c,v
retrieving revision 1.70

net/netsyms.c +0 -71

83 lines not on this page · raw message

Index: linux/net/core/skbuff.c
===================================================================
RCS file: /home/cvs/linux-2.5/net/core/skbuff.c,v
retrieving revision 1.26

net/core/skbuff.c +1 -1
diff -u -r1.26 skbuff.c
@@ -225,7 +225,7 @@
 	}
 
 	dst_release(skb->dst);
-#ifdef CONFIG_INET
+#ifdef CONFIG_XFRM
 	secpath_put(skb->sp);
 #endif
 	if(skb->destructor) {

Index: linux/net/ipv4/Kconfig
===================================================================
RCS file: /home/cvs/linux-2.5/net/ipv4/Kconfig,v
retrieving revision 1.8

net/ipv4/Kconfig +5 -0
diff -u -r1.8 Kconfig
@@ -187,6 +187,7 @@
 config NET_IPIP
 	tristate "IP: tunneling"
 	depends on INET
+	select XFRM
 	---help---
 	  Tunneling means encapsulating data of one protocol type within
 	  another protocol and sending it over a channel that understands the
@@ -205,6 +206,7 @@
 config NET_IPGRE
 	tristate "IP: GRE tunnels over IP"
 	depends on INET
+	select XFRM
 	help
 	  Tunneling means encapsulating data of one protocol type within
 	  another protocol and sending it over a channel that understands the
@@ -343,6 +345,7 @@
 
 config INET_AH
 	tristate "IP: AH transformation"
+	select XFRM
 	select CRYPTO
 	select CRYPTO_HMAC
 	select CRYPTO_MD5
@@ -354,6 +357,7 @@
 
 config INET_ESP
 	tristate "IP: ESP transformation"
+	select XFRM
 	select CRYPTO
 	select CRYPTO_HMAC
 	select CRYPTO_MD5
@@ -366,6 +370,7 @@
 
 config INET_IPCOMP
 	tristate "IP: IPComp transformation"
+	select XFRM
 	select CRYPTO
 	select CRYPTO_DEFLATE
 	---help---

Index: linux/net/ipv4/Makefile
===================================================================
RCS file: /home/cvs/linux-2.5/net/ipv4/Makefile,v
retrieving revision 1.19

net/ipv4/Makefile +1 -1
diff -u -r1.19 Makefile
@@ -22,4 +22,4 @@
 obj-$(CONFIG_IP_PNP) += ipconfig.o
 obj-$(CONFIG_NETFILTER)	+= netfilter/
 
-obj-y += xfrm4_policy.o xfrm4_state.o xfrm4_input.o xfrm4_tunnel.o
+obj-$(CONFIG_XFRM) += xfrm4_policy.o xfrm4_state.o xfrm4_input.o xfrm4_tunnel.o

Index: linux/net/ipv4/route.c
===================================================================
RCS file: /home/cvs/linux-2.5/net/ipv4/route.c,v
retrieving revision 1.52

net/ipv4/route.c +2 -0
diff -u -r1.52 route.c
@@ -2727,8 +2727,10 @@
 	create_proc_read_entry("net/rt_acct", 0, 0, ip_rt_acct_read, NULL);
 #endif
 #endif
+#ifdef CONFIG_XFRM
 	xfrm_init();
 	xfrm4_init();
+#endif
 out:
 	return rc;
 out_enomem:

Index: linux/net/ipv4/udp.c
===================================================================
RCS file: /home/cvs/linux-2.5/net/ipv4/udp.c,v
retrieving revision 1.34

net/ipv4/udp.c +7 -2
diff -u -r1.34 udp.c
@@ -945,6 +945,9 @@
  */
 static int udp_encap_rcv(struct sock * sk, struct sk_buff *skb)
 {
+#ifndef CONFIG_XFRM
+	return 1; 
+#else
 	struct udp_opt *up = udp_sk(sk);
   	struct udphdr *uh = skb->h.uh;
 	struct iphdr *iph;
@@ -1004,10 +1007,12 @@
 		return -1;
 
 	default:
-		printk(KERN_INFO "udp_encap_rcv(): Unhandled UDP encap type: %u\n",
-		       encap_type);
+		if (net_ratelimit())
+			printk(KERN_INFO "udp_encap_rcv(): Unhandled UDP encap type: %u\n",
+			       encap_type);
 		return 1;
 	}
+#endif
 }
 
 /* returns:

Index: linux/net/ipv6/Kconfig
===================================================================
RCS file: /home/cvs/linux-2.5/net/ipv6/Kconfig,v
retrieving revision 1.7

net/ipv6/Kconfig +5 -0
diff -u -r1.7 Kconfig
@@ -4,6 +4,7 @@
 config IPV6_PRIVACY
 	bool "IPv6: Privacy Extensions (RFC 3041) support"
 	depends on IPV6
+	select XFRM
 	select CRYPTO
 	select CRYPTO_MD5
 	---help---
@@ -22,6 +23,7 @@
 config INET6_AH
 	tristate "IPv6: AH transformation"
 	depends on IPV6
+	select XFRM
 	select CRYPTO
 	select CRYPTO_HMAC
 	select CRYPTO_MD5
@@ -34,6 +36,7 @@
 config INET6_ESP
 	tristate "IPv6: ESP transformation"
 	depends on IPV6
+	select XFRM
 	select CRYPTO
 	select CRYPTO_HMAC
 	select CRYPTO_MD5
@@ -47,6 +50,7 @@
 config INET6_IPCOMP
 	tristate "IPv6: IPComp transformation"
 	depends on IPV6
+	select XFRM
 	select CRYPTO
 	select CRYPTO_DEFLATE
 	---help---
@@ -57,6 +61,7 @@
 
 config IPV6_TUNNEL
 	tristate "IPv6: IPv6-in-IPv6 tunnel"
+	select XFRM
 	depends on IPV6
 	---help---
 	  Support for IPv6-in-IPv6 tunnels described in RFC 2473.

Index: linux/net/ipv6/Makefile
===================================================================
RCS file: /home/cvs/linux-2.5/net/ipv6/Makefile,v
retrieving revision 1.15

net/ipv6/Makefile +3 -2
diff -u -r1.15 Makefile
@@ -8,8 +8,9 @@
 		route.o ip6_fib.o ipv6_sockglue.o ndisc.o udp.o raw.o \
 		protocol.o icmp.o mcast.o reassembly.o tcp_ipv6.o \
 		exthdrs.o sysctl_net_ipv6.o datagram.o proc.o \
-		ip6_flowlabel.o ipv6_syms.o \
-		xfrm6_policy.o xfrm6_state.o xfrm6_input.o
+		ip6_flowlabel.o ipv6_syms.o
+
+obj-$(CONFIG_XFRM) += xfrm6_policy.o xfrm6_state.o xfrm6_input.o
 
 obj-$(CONFIG_INET6_AH) += ah6.o
 obj-$(CONFIG_INET6_ESP) += esp6.o

Index: linux/net/ipv6/ipv6_syms.c
===================================================================
RCS file: /home/cvs/linux-2.5/net/ipv6/ipv6_syms.c,v retrieving revision 1.16

net/ipv6/ipv6_syms.c +2 -0
diff -u -r1.16 ipv6_syms.c
@@ -36,8 +36,10 @@
 EXPORT_SYMBOL(in6addr_loopback);
 EXPORT_SYMBOL(in6_dev_finish_destroy);
 EXPORT_SYMBOL(ip6_find_1stfragopt);
+#ifdef CONFIG_XFRM
 EXPORT_SYMBOL(xfrm6_rcv);
 EXPORT_SYMBOL(xfrm6_clear_mutable_options);
+#endif
 EXPORT_SYMBOL(rt6_lookup);
 EXPORT_SYMBOL(fl6_sock_lookup);
 EXPORT_SYMBOL(ipv6_ext_hdr);

Index: linux/net/ipv6/route.c
===================================================================
RCS file: /home/cvs/linux-2.5/net/ipv6/route.c,v
retrieving revision 1.40

net/ipv6/route.c +2 -0
diff -u -r1.40 route.c
@@ -1915,7 +1915,9 @@
 	if (p)
 		p->proc_fops = &rt6_stats_seq_fops;
 #endif
+#ifdef CONFIG_XFRM
 	xfrm6_init();
+#endif
 }
 
 #ifdef MODULE

Index: linux/net/xfrm/Kconfig
===================================================================
RCS file: /home/cvs/linux-2.5/net/xfrm/Kconfig,v
retrieving revision 1.2

net/xfrm/Kconfig +5 -1
diff -u -r1.2 Kconfig
@@ -1,9 +1,13 @@
 #
 # XFRM configuration
 #
+config XFRM
+       bool
+       depends on NET
+
 config XFRM_USER
 	tristate "IPsec user configuration interface"
-	depends on INET
+	depends on INET && XFRM
 	---help---
 	  Support for IPsec user configuration interface used
 	  by native Linux tools.

Index: linux/net/xfrm/Makefile
===================================================================
RCS file: /home/cvs/linux-2.5/net/xfrm/Makefile,v
retrieving revision 1.3

net/xfrm/Makefile +2 -1
diff -u -r1.3 Makefile
@@ -2,6 +2,7 @@
 # Makefile for the XFRM subsystem.
 #
 
-obj-y := xfrm_policy.o xfrm_state.o xfrm_input.o xfrm_algo.o xfrm_output.o
+obj-$(CONFIG_XFRM) := xfrm_policy.o xfrm_state.o xfrm_input.o xfrm_algo.o xfrm_output.o \
+	xfrm_export.o
 obj-$(CONFIG_XFRM_USER) += xfrm_user.o
 
net/xfrm/xfrm_export.c new file +74 -0

74 lines not on this page · raw message

#1 lore raw

From: Andi Kleen <[email protected]>
Date: Sat, 14 Jun 2003 11:16:31 +0200

This patches only compiles the xfrm subsystem in when any of the options using it are selected. This shrinks the text segment on an amd64 kernel by ~32k, data by ~6k, bss by ~33k, overall ~72K memory saved.

I'm not going to apply this, sorry Andi.

I want the freedom to use the XFRM layer for generic things at some point.

How about working on making the xfrm layer more lean instead? :)

author
#2 lore raw
Quoted 11 lines · David S. Miller

From: Andi Kleen <[email protected]>
Date: Sat, 14 Jun 2003 11:16:31 +0200

This patches only compiles the xfrm subsystem in when any of the options using it are selected. This shrinks the text segment on an amd64 kernel by ~32k, data by ~6k, bss by ~33k, overall ~72K memory saved.

I'm not going to apply this, sorry Andi.

I want the freedom to use the XFRM layer for generic things at some point.

But in 2.7 surely right? When what happens you can easily make CONFIG_XFRM the default. This would give the 2.6 users an useful option.

Also when you do use it generically you will hopefully discard some old code (like the rt cache?) which may make up for the additional bloat. But until that happens having both even when not needed doesn't make too much sense.

Quoted 2 lines

How about working on making the xfrm layer more lean instead? :)

My last proposal for this (using hlists in the hash tables) was rejected, so I don't see much chance to do this.

-Andi

#3 lore raw

From: Andi Kleen <[email protected]>
Date: Sat, 14 Jun 2003 11:36:30 +0200

Also when you do use it generically you will hopefully discard some old code (like the rt cache?) which may make up for the additional bloat. But until that happens having both even when not needed doesn't make too much sense.

The rtcache will likely be retained as a flow cache lookup miss handler even once we use the flowcache for all lookups.

Actually, that entire area is in flux, I still do not know the fate of the rtcache even without the flow cache :)

Quoted 1 line

How about working on making the xfrm layer more lean instead? :)

My last proposal for this (using hlists in the hash tables) was rejected, so I don't see much chance to do this.

Because hlists cannot retain the behavior we need, specifically because we need the ability to add to the tail.

If it's some in-kernel-image table, why not dynamically allocate the table in question?

author
#4 lore raw
Quoted 8 lines · David S. Miller

From: Andi Kleen <[email protected]>
Date: Sat, 14 Jun 2003 11:36:30 +0200

Also when you do use it generically you will hopefully discard some old code (like the rt cache?) which may make up for the additional bloat. But until that happens having both even when not needed doesn't make too much sense.

Quoted 5 lines

The rtcache will likely be retained as a flow cache lookup miss handler even once we use the flowcache for all lookups.

Actually, that entire area is in flux, I still do not know the fate of the rtcache even without the flow cache :)

In that case you could really apply the patch. It doesn't close any future options for you, just makes live a bit better for some users today.

Quoted 11 lines
Quoted 2 lines

How about working on making the xfrm layer more lean instead? :)

My last proposal for this (using hlists in the hash tables) was rejected, so I don't see much chance to do this.

Because hlists cannot retain the behavior we need, specifically because we need the ability to add to the tail.

If it's some in-kernel-image table, why not dynamically allocate the table in question?

Allocating it at first lookup would be racy (would need a nasty spinlock at least). It may be possible at first policy setup, but it's not guaranteed you can still get two 32K continuous areas. You could fall back to vmalloc I guess.

Allocating it at bootup would be equivalent to the current BSS allocation.

Advantage of the dynamic allocation is that it would work for vendor kernels also.

-Andi

#5 lore raw

From: Andi Kleen <[email protected]>
Date: Sat, 14 Jun 2003 12:18:51 +0200

Allocating it at first lookup would be racy (would need a nasty spinlock at least). It may be possible at first policy setup, but it's not guaranteed you can still get two 32K continuous areas. You could fall back to vmalloc I guess.

Andi, you're getting rediculious. Add a xfrm_whatever_init() call and allocate the table there.

Oh, I see, we do that already... end of discussion I guess.

author
#6 lore raw
Quoted 10 lines · David S. Miller

From: Andi Kleen <[email protected]>
Date: Sat, 14 Jun 2003 12:18:51 +0200

Allocating it at first lookup would be racy (would need a nasty spinlock at least). It may be possible at first policy setup, but it's not guaranteed you can still get two 32K continuous areas. You could fall back to vmalloc I guess.

Andi, you're getting rediculious. Add a xfrm_whatever_init() call and allocate the table there.

Did you actually read what I wrote? Allocating on init is useless from the bloat perspective because it's 100% equivalent to an BSS allocation.

-Andi

#7 lore raw

decorum

Could we please have less ad-hominem invective
and less profanity on this list?

If you have a good point to make, making it
politely costs you nothing.

You know who you are.

#8 lore raw

Re: decorum

You sound like the NANOG bitch. If your ears can't handle hearing "fuck" now and then, get off the net and back to your bible study group.

Ralph Doncaster, president
6042147 Canada Inc. o/a IStop.com

Quoted 10 lines · John S. Denker

Could we please have less ad-hominem invective
and less profanity on this list?

If you have a good point to make, making it
politely costs you nothing.

You know who you are.

#10 lore raw
In reply to Andi Kleen

From: Andi Kleen <[email protected]>
Date: Sat, 14 Jun 2003 20:32:32 +0200

Quoted 10 lines · David S. Miller

From: Andi Kleen <[email protected]>
Date: Sat, 14 Jun 2003 12:18:51 +0200

Allocating it at first lookup would be racy (would need a nasty spinlock at least). It may be possible at first policy setup, but it's not guaranteed you can still get two 32K continuous areas. You could fall back to vmalloc I guess.

Andi, you're getting rediculious. Add a xfrm_whatever_init() call and allocate the table there.

Did you actually read what I wrote? Allocating on init is useless from the bloat perspective because it's 100% equivalent to an BSS allocation.

If dynamic, you could allocate a "tiny" hash table or whatever on bootup and grow it as usage increases, much like we grow the FIB hashes dynamically.

#9 lore raw

Re: decorum

In reply to Ralph Doncaster

From: Ralph Doncaster <[email protected]>
Date: Sat, 14 Jun 2003 18:02:53 -0400 (EDT)

You sound like the NANOG bitch. If your ears can't handle hearing "fuck" now and then, get off the net and back to your bible study group.

I totally agree, this isn't a family list.

author
#11 lore raw
In reply to David S. Miller
Quoted 15 lines · David S. Miller

From: Andi Kleen <[email protected]>
Date: Sat, 14 Jun 2003 20:32:32 +0200

Quoted 10 lines · David S. Miller

From: Andi Kleen <[email protected]>
Date: Sat, 14 Jun 2003 12:18:51 +0200

Allocating it at first lookup would be racy (would need a nasty spinlock at least). It may be possible at first policy setup, but it's not guaranteed you can still get two 32K continuous areas. You could fall back to vmalloc I guess.

Andi, you're getting rediculious. Add a xfrm_whatever_init() call and allocate the table there.

Quoted 7 lines

Did you actually read what I wrote? Allocating on init is useless from the bloat perspective because it's 100% equivalent to an BSS allocation.

If dynamic, you could allocate a "tiny" hash table or whatever on bootup and grow it as usage increases, much like we grow the FIB hashes dynamically.

I suspect dynamic growing at runtime would result in interesting SMP locking issues (suspect - i haven't studied the xfrm locking in detail yet)

Also it has the same problem - 32K direct mapping allocation may not work anymore during runtime.

I can take a look later if something else can be improved, but I'm not very optimistic (the design of this thing is just not lightweight neither in code nor data structures)
Especially since you already vetoed the two best looking options.

It is just another inetpeer cache, a sleeping gigant waiting mostly unused for its great days ;)

-Andi