Skip to contentSkip to conversation

iproute2: add option to build m_xt as a tc module.

PATCH In review Andreas Henriksson 2 participants 6 messages Apr 12, 2010

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

PATCH 1/1 iproute2: add option to build m_xt as a tc module.

Add TC_CONFIG_XT_MODULE option that can be added
either to Config (after ./configure) or as an argument to "make".

This will build the xt module (action ipt) of tc as a shared object that is linked at runtime by tc if used, rather then built into tc.

This is similar to how the atm qdisc support
is handled (q_atm.so).

---

The reason for this is simply to be able to avoid the tc binary from being linked to libxtables. This way distributions who ship binary packages can avoid a dependency on the iptables package by ignoring m_xt.so in the dependency analysis and let actual users of the tc arguments "action ipt" make sure they have iptables installed.
(See http://bugs.debian.org/576953 )

This was not a problem with the old/deprecated m_ipt module which did runtime linking of
the iptables library.

Having the split inside tc, rather then between tc and the required library, is preferred. This way we'll notice at build-time when the required library breaks API/ABI rather
then having to rely on people that uses the functionality to report back when the ABI is broken.
(We've learned this the hard way in debian after many angry bugreports.)

I've had jamal pre-review this and he didn't see any problems with this.

tc/Makefile +13 -7
index 805c108..3af33cf 100644
@@ -43,10 +43,18 @@ TCMODULES += em_cmp.o
 TCMODULES += em_u32.o
 TCMODULES += em_meta.o
 
+TCSO :=
+ifeq ($(TC_CONFIG_ATM),y)
+  TCSO += q_atm.so
+endif
 
 ifeq ($(TC_CONFIG_XT),y)
-  TCMODULES += m_xt.o
-  LDLIBS += -lxtables
+  ifeq ($(TC_CONFIG_XT_MODULE),y)
+    TCSO += m_xt.so
+  else
+    TCMODULES += m_xt.o
+    LDLIBS += -lxtables
+  endif
 else
   ifeq ($(TC_CONFIG_XT_OLD),y)
     TCMODULES += m_xt_old.o
@@ -81,11 +89,6 @@ ifneq ($(IPT_LIB_DIR),)
 	CFLAGS += -DIPT_LIB_DIR=\"$(IPT_LIB_DIR)\"
 endif
 
-TCSO :=
-ifeq ($(TC_CONFIG_ATM),y)
-  TCSO += q_atm.so
-endif
-
 YACC := bison
 LEX := flex
 
@@ -114,6 +117,9 @@ clean:
 q_atm.so: q_atm.c
 	$(CC) $(CFLAGS) $(LDFLAGS) -shared -fpic -o q_atm.so q_atm.c -latm
 
+m_xt.so: m_xt.c
+	$(CC) $(CFLAGS) $(LDFLAGS) -shared -fpic -o m_xt.so m_xt.c -lxtables
+
 %.yacc.c: %.y
 	$(YACC) $(YACCFLAGS) -o $@ $<
 
#1 lore raw
Quoted 2 lines · On Mon, 12 Apr 2010 13:55:38 +0200 Andreas Henriksson <[email protected]> wrote:

Add TC_CONFIG_XT_MODULE option that can be added
either to Config (after ./configure) or as an argument to "make".

I like the idea and will incorporate it, but do not like having more build options. Adding more configuration options like this is just lazy design "we can't figure this out, let's make the user do it".

So put the patch in but there it will always be true.

#2 lore raw
Quoted 11 lines · Stephen Hemminger
Quoted 2 lines · On Mon, 12 Apr 2010 13:55:38 +0200 Andreas Henriksson <[email protected]> wrote:

Add TC_CONFIG_XT_MODULE option that can be added
either to Config (after ./configure) or as an argument to "make".

I like the idea and will incorporate it, but do not like having more build options. Adding more configuration options like this is just lazy design "we can't figure this out, let's make the user do it".

So put the patch in but there it will always be true.

Sure..... unfortunately I found problems for the patch to work. (dlopen needs full path and module name needs to match action name) Will send new patch as a followup to this mail.

Note: I'm not a user of any of this functionality. (including "make install"!) I've tried testing "action ipt" with m_xt.so now, but m_xt_old.so is completely untested!

I used the following command when testing m_xt.so:
tc qdisc add dev lo ingress
tc filter add dev lo parent ffff: protocol ip prio 1 u32 match ip src 127.1.1.1/32 action ipt -j FOOBAR

...which gave me the error "failed to find target FOOBAR",
and this is to me an indication of success since I don't have that target.

Signature · 1 line
Andreas Henriksson
#3 lore raw

PATCH 1/1 iproute2: add option to build m_xt as a tc module (v2)

This will build the xt module (action ipt) of tc as a shared object that is linked at runtime by tc if used, rather then built into tc.

This is similar to how the atm qdisc support
is handled (q_atm.so).

---

v2:
Updated to not be a configurable option, always
build as module.
Also build m_xt_old as module (untested!).
Give dlopen full path to modules rather then just filename. Fix make install module destination directory problems (untested!).

tc/Makefile +25 -14
index 805c108..23dbca8 100644
@@ -43,19 +43,20 @@ TCMODULES += em_cmp.o
 TCMODULES += em_u32.o
 TCMODULES += em_meta.o
 
+TCSO :=
+ifeq ($(TC_CONFIG_ATM),y)
+  TCSO += q_atm.so
+endif
 
 ifeq ($(TC_CONFIG_XT),y)
-  TCMODULES += m_xt.o
-  LDLIBS += -lxtables
+  TCSO += m_xt.so
 else
   ifeq ($(TC_CONFIG_XT_OLD),y)
-    TCMODULES += m_xt_old.o
-    LDLIBS += -lxtables
+    TCSO += m_xt_old.so
   else
     ifeq ($(TC_CONFIG_XT_OLD_H),y)
 	CFLAGS += -DTC_CONFIG_XT_H
-	TCMODULES += m_xt_old.o
-	LDLIBS += -lxtables
+	TCSO += m_xt_old.so
     else
       TCMODULES += m_ipt.o
     endif
@@ -81,14 +82,11 @@ ifneq ($(IPT_LIB_DIR),)
 	CFLAGS += -DIPT_LIB_DIR=\"$(IPT_LIB_DIR)\"
 endif
 
-TCSO :=
-ifeq ($(TC_CONFIG_ATM),y)
-  TCSO += q_atm.so
-endif
-
 YACC := bison
 LEX := flex
 
+MODDESTDIR := $(DESTDIR)$(patsubst /usr%,%,$(LIBDIR))/tc
+
 %.so: %.c
 	$(CC) $(CFLAGS) $(LDFLAGS) -shared -fpic $< -o $@
 
@@ -101,11 +99,18 @@ libtc.a: $(TCLIB)
 	$(AR) rcs $@ $(TCLIB)
 
 install: all
-	mkdir -p $(DESTDIR)$(LIBDIR)/tc
-	install -m 0755 tc $(DESTDIR)$(SBINDIR)
+	echo mkdir -p $(MODDESTDIR)
+	echo install -m 0755 tc $(DESTDIR)$(SBINDIR)
 	for i in $(TCSO); \
-	do install -m 755 $$i $(DESTDIR)$(LIBDIR)/tc; \
+	do echo install -m 755 $$i $(MODDESTDIR); \
 	done
+	if [ ! -f $(MODDESTDIR)/m_ipt.so ]; then \
+	if [ -f $(MODDESTDIR)/m_xt.so ]; \
+		then ln -s m_xt.so $(MODDESTDIR)/m_ipt.so ; \
+	elif [ -f $(MODDESTDIR)/m_xt_old.so ]; \
+		then ln -s m_xt_old.so $(MODDESTDIR)/m_ipt.so ; \
+	fi; \
+	fi
 
 clean:
 	rm -f $(TCOBJ) $(TCLIB) libtc.a tc *.so emp_ematch.yacc.h; \
@@ -114,6 +119,12 @@ clean:
 q_atm.so: q_atm.c
 	$(CC) $(CFLAGS) $(LDFLAGS) -shared -fpic -o q_atm.so q_atm.c -latm
 
+m_xt.so: m_xt.c
+	$(CC) $(CFLAGS) $(LDFLAGS) -shared -fpic -o m_xt.so m_xt.c -lxtables
+
+m_xt_old.so: m_xt_old.c
+	$(CC) $(CFLAGS) $(LDFLAGS) -shared -fpic -o m_xt.so m_xt.c -lxtables
+
 %.yacc.c: %.y
 	$(YACC) $(YACCFLAGS) -o $@ $<
 
tc/m_action.c +1 -1
index 9f24022..a198158 100644
@@ -98,7 +98,7 @@ restart_s:
 			return a;
 	}
 
-	snprintf(buf, sizeof(buf), "m_%s.so", str);
+	snprintf(buf, sizeof(buf), "%s/m_%s.so", get_tc_lib(), str);
 	dlh = dlopen(buf, RTLD_LAZY);
 	if (dlh == NULL) {
 		dlh = aBODY;
#4 lore raw

PATCH 1/1 iproute2: add option to build m_xt as a tc module (v3)

This will build the xt module (action ipt) of tc as a shared object that is linked at runtime by tc if used, rather then built into tc.

This is similar to how the atm qdisc support
is handled (q_atm.so).

---

v3:
fix cut'n'paste problem in m_xt_old.so make rule. SORRY!

v2:
Updated to not be a configurable option, always
build as module.
Also build m_xt_old as module (untested!).
Give dlopen full path to modules rather then just filename. Fix make install module destination directory problems (untested!).

tc/Makefile +25 -14
index 805c108..01a16fc 100644
@@ -43,19 +43,20 @@ TCMODULES += em_cmp.o
 TCMODULES += em_u32.o
 TCMODULES += em_meta.o
 
+TCSO :=
+ifeq ($(TC_CONFIG_ATM),y)
+  TCSO += q_atm.so
+endif
 
 ifeq ($(TC_CONFIG_XT),y)
-  TCMODULES += m_xt.o
-  LDLIBS += -lxtables
+  TCSO += m_xt.so
 else
   ifeq ($(TC_CONFIG_XT_OLD),y)
-    TCMODULES += m_xt_old.o
-    LDLIBS += -lxtables
+    TCSO += m_xt_old.so
   else
     ifeq ($(TC_CONFIG_XT_OLD_H),y)
 	CFLAGS += -DTC_CONFIG_XT_H
-	TCMODULES += m_xt_old.o
-	LDLIBS += -lxtables
+	TCSO += m_xt_old.so
     else
       TCMODULES += m_ipt.o
     endif
@@ -81,14 +82,11 @@ ifneq ($(IPT_LIB_DIR),)
 	CFLAGS += -DIPT_LIB_DIR=\"$(IPT_LIB_DIR)\"
 endif
 
-TCSO :=
-ifeq ($(TC_CONFIG_ATM),y)
-  TCSO += q_atm.so
-endif
-
 YACC := bison
 LEX := flex
 
+MODDESTDIR := $(DESTDIR)$(patsubst /usr%,%,$(LIBDIR))/tc
+
 %.so: %.c
 	$(CC) $(CFLAGS) $(LDFLAGS) -shared -fpic $< -o $@
 
@@ -101,11 +99,18 @@ libtc.a: $(TCLIB)
 	$(AR) rcs $@ $(TCLIB)
 
 install: all
-	mkdir -p $(DESTDIR)$(LIBDIR)/tc
-	install -m 0755 tc $(DESTDIR)$(SBINDIR)
+	echo mkdir -p $(MODDESTDIR)
+	echo install -m 0755 tc $(DESTDIR)$(SBINDIR)
 	for i in $(TCSO); \
-	do install -m 755 $$i $(DESTDIR)$(LIBDIR)/tc; \
+	do echo install -m 755 $$i $(MODDESTDIR); \
 	done
+	if [ ! -f $(MODDESTDIR)/m_ipt.so ]; then \
+	if [ -f $(MODDESTDIR)/m_xt.so ]; \
+		then ln -s m_xt.so $(MODDESTDIR)/m_ipt.so ; \
+	elif [ -f $(MODDESTDIR)/m_xt_old.so ]; \
+		then ln -s m_xt_old.so $(MODDESTDIR)/m_ipt.so ; \
+	fi; \
+	fi
 
 clean:
 	rm -f $(TCOBJ) $(TCLIB) libtc.a tc *.so emp_ematch.yacc.h; \
@@ -114,6 +119,12 @@ clean:
 q_atm.so: q_atm.c
 	$(CC) $(CFLAGS) $(LDFLAGS) -shared -fpic -o q_atm.so q_atm.c -latm
 
+m_xt.so: m_xt.c
+	$(CC) $(CFLAGS) $(LDFLAGS) -shared -fpic -o m_xt.so m_xt.c -lxtables
+
+m_xt_old.so: m_xt_old.c
+	$(CC) $(CFLAGS) $(LDFLAGS) -shared -fpic -o m_xt_old.so m_xt_old.c -lxtables
+
 %.yacc.c: %.y
 	$(YACC) $(YACCFLAGS) -o $@ $<
 
tc/m_action.c +1 -1
index 9f24022..a198158 100644
@@ -98,7 +98,7 @@ restart_s:
 			return a;
 	}
 
-	snprintf(buf, sizeof(buf), "m_%s.so", str);
+	snprintf(buf, sizeof(buf), "%s/m_%s.so", get_tc_lib(), str);
 	dlh = dlopen(buf, RTLD_LAZY);
 	if (dlh == NULL) {
 		dlh = aBODY;
#5 lore raw

Re: [PATCH] iproute2: add option to build m_xt as a tc module (v3)

Quoted 8 lines · On Mon, 12 Apr 2010 20:24:23 +0200 Andreas Henriksson <[email protected]> wrote:

This will build the xt module (action ipt) of tc as a shared object that is linked at runtime by tc if used, rather then built into tc.

This is similar to how the atm qdisc support
is handled (q_atm.so).

Applied thanks.