Commit Graph

36 Commits

Author SHA1 Message Date
Stephen Hemminger
d5ddb441a5 tc: print all error messages to stderr
Many tc modules were printing error messages to stdout.
This is problematic if using JSON or other output formats.
Change all these places to use fprintf(stderr, ...) instead.

Also, remove unnecessary initialization and places
where else is used after error return.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
2019-07-11 15:35:07 -07:00
Stephen Hemminger
6f1940da8e tc: replace left side comparison
The kernel (and iproute2) don't use the if (NULL == x) style
and instead prefer if (!x)

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
Signed-off-by: David Ahern <dsahern@gmail.com>
2019-01-28 08:51:03 -08:00
Serhey Popovych
c14f9d92ee treewide: Use addattr_nest()/addattr_nest_end() to handle nested attributes
We have helper routines to support nested attribute addition into
netlink buffer: use them instead of open coding.

Use addattr_nest_compat()/addattr_nest_compat_end() where appropriate.

Signed-off-by: Serhey Popovych <serhe.popovych@gmail.com>
Signed-off-by: David Ahern <dsahern@gmail.com>
2018-02-02 15:01:09 -08:00
Stephen Hemminger
b317557f58 tc: replace magic constant 16 with #define
For places where tc is expecting device name use IFNAMSIZ.
For others where it is a filter name, introduce a new constant.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
2017-11-24 11:19:18 -08:00
Stephen Hemminger
913352fe54 drop unneeded include of syslog.h
Only arpd uses syslog

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
2017-11-12 16:22:36 -08:00
Roman Mashak
530753184a tc: pass correct conversion specifier to print 'unsigned int' action index.
Signed-off-by: Roman Mashak <mrv@mojatatu.com>
Signed-off-by: Jamal Hadi Salim <jhs@mojatatu.com>
2016-12-14 19:00:36 -08:00
Phil Sutter
f89bb0210f Replace malloc && memset by calloc
This only replaces occurrences where the newly allocated memory is
cleared completely afterwards, as in other cases it is a theoretical
performance hit although code would be cleaner this way.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Acked-by: David Ahern <dsa@cumulusnetworks.com>
2016-07-20 12:05:24 -07:00
Alexander Aring
9b32f89693 tc: let m_ipt work with new iptables API headers
Since commit 5cd1adb ("Update to current iptables headers") the build
with m_ipt.o and the following config will fail:

TC_CONFIG_XT:=n
TC_CONFIG_XT_OLD:=n
TC_CONFIG_XT_OLD_H:=n

This patch renames "iptables_target" to "xtables_target" and some other
things which gets renamed and I noticed while reading iptables git log.
Functions which are not used in m_ipt.c and not exported by the header
are removed, if they still used in m_ipt.c I added a static to the function.

Reported-by: Clemens Gruber <clemens.gruber@pqgruber.com>
Signed-off-by: Alexander Aring <aar@pengutronix.de>
2016-06-14 18:03:30 -07:00
Stephen Hemminger
32a121cba2 tc: code cleanup
Use checkpatch to fix whitespace and other style issues.
2016-03-21 11:48:36 -07:00
Stephen Hemminger
753ef5bbd6 tc: remove extra whitespace
No blank lines at EOF, or trailing whitespace.
2015-10-23 15:43:28 -07:00
Stephen Hemminger
3d0b7439df whitespace cleanup
Remove all trailing whitespace and space before tabs.
2014-12-20 15:47:17 -08:00
Stephen Hemminger
b8a45897b9 More minor spelling fixes 2013-08-04 15:10:05 -07:00
Stephen Hemminger
ff24746cca Convert to use rta_getattr_ functions
User new functions (inspired by libmnl) to do type safe access
of routeing attributes
2012-04-10 08:47:55 -07:00
Thomas Jarosch
a3da01c519 tc: Remove unused variable 'res'.
Detected by cppcheck.

Signed-off-by: Thomas Jarosch <thomas.jarosch@intra2net.com>
2011-11-23 14:46:21 -08:00
Thomas Jarosch
1a6543c56b Fix memory leak of lname variable in get_target_name()
Detected by cppcheck.

Signed-off-by: Thomas Jarosch <thomas.jarosch@intra2net.com>
2011-10-07 11:17:10 -07:00
Mike Frysinger
f2e27cfb01 support static-only systems
The iptables code supports a "no shared libs" mode where it can be used
without requiring dlfcn related functionality.  This adds similar support
to iproute2 so that it can easily be used on systems like nommu Linux (but
obviously with a few limitations -- no dynamic plugins).

Rather than modify every location that uses dlfcn.h, I hooked the dlfcn.h
header with stub functions when shared library support is disabled.  Then
symbol lookup is done via a local static lookup table (which is generated
automatically at build time) so that internal symbols can be found.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
2009-11-10 10:44:20 -08:00
Stephen Hemminger
52d6a85050 remove duplicate limits.h 2009-03-27 11:07:46 -07:00
Denys Fedoryschenko
a589dcda9c Fix memory leak in local options
This change was forgotten by Stephen in the last release

Signed-off-by: Denys Fedoryschenko <denys@visp.net.lb>
Signed-off-by: Jamal Hadi Salim <hadi@cyberus.ca>
2009-02-19 09:04:06 -08:00
Stephen Hemminger
bdc213423a Fix leftovers from earlier change
Still had references to l_name.
2009-01-07 17:20:14 -08:00
Denys Fedoryshchenko
6e34e7dc0a Fix tc/m_ipt memory leaks
1)optind according iptables sources have to be set to 0. If it is set to 1, in
batch it will mess up things. Also in iptables sources i notice that ->tflags
and ->used need to be reset.

2)Since target->t = fw_calloc(1, size); allocated memory in function build_st,
it have to be freed at the end, or in batch we will have memory leak. TODO:
Probably it must be freed in all "return -1" cases in parse_ipt after
build_st. About this i am not sure, up to Stephen.

3)new_name was malloc'ed, but not freed
2009-01-06 19:46:11 -08:00
Stephen Hemminger
4c7abb271b Merge branch 'master' into net-2.6.25 2007-12-31 12:51:15 -08:00
Denys Fedoryshchenko
53c017880b iptables compatiablity
New iptables 1.4.0 has some library names changed from libipt to libxt.
It is prefferable also to open libxt_ first, as newer "style".

Signed-off-by: Denys Fedoryshchenko <nuclearcat@nuclearcat.com>
Signed-off-by: Jamal Hadi Salim <hadi@cyberus.ca>
Signed-off-by: Stephen Hemminger <stephen.hemminger@vyatta.com>
2007-12-31 11:15:29 -08:00
Stephen Hemminger
ece02ea0a3 Fix breakage from netfilter/ip_tables header change.
Signed-off-by: Stephen Hemminger <shemminger@linux-foundation.org>
2007-12-10 09:40:45 -08:00
Stephen Hemminger
f7cd9b0354 Fix m_ipt build
Signed-off-by: Stephen Hemminger <shemminger@linux-foundation.org>
2007-08-22 10:33:33 -07:00
Patrick McHardy
c6ab5b8247 [Fwd: Re: more iproute2 issues (not critical)]
This one also makes sense for the release I guess.

-------- Original Message --------
Subject: 	Re: more iproute2 issues (not critical)
Date: 	Sat, 31 Mar 2007 16:16:56 +0200
From: 	Patrick McHardy <kaber@trash.net>
To: 	Denys <denys@visp.net.lb>
CC: 	Stephen Hemminger <shemminger@linux-foundation.org>,
netdev@vger.kernel.org
References: 	<20070321175951.M73913@visp.net.lb>
<46026717.9060909@trash.net> <20070322124533.M79867@visp.net.lb>
<46027FF2.6020001@trash.net> <20070322101224.3e6bb899@freekitty>
<20070331021401.M17326@visp.net.lb> <20070331023011.M8101@visp.net.lb>

Denys wrote:
> Ooops, sorry, it seems my fault, no library exist on this system.
> But i guess it must not coredump in this case? Is it possible to check if
> library not exist and just print some nice message?
> It is trivial i guess.

The problem is that lib_dir is NULL when calling get_target_names.
This patch fixes it.

[IPROUTE]: m_ipt: fix crash when dumping rules

lib_dir is NULL when calling get_target_name, causing a NULL pointer
dereference in the strlen call.

Signed-off-by: Patrick McHardy <kaber@trash.net>
2007-06-20 10:52:22 -07:00
jamal
9aa446896e Old bug on tc
> It is in current git tree.

A small fix attached after some testing.
Please dont forget to apply my other patches. When you have them let me
know so i can do some more testing.

cheers,
jamal

[TC] Get iptables path selection to set correct path

A small tweak on top of Stephens patch

Signed-off-by: Jamal Hadi Salim <hadi@cyberus.ca>
Signed-off-by: Stephen Hemminger <shemminger@linux-foundation.org>
2007-03-13 14:43:24 -07:00
Stephen Hemminger
de539ecf6c iptables library fix
Don't hard code iptables library path. Allow use of environment variable.

Signed-off-by: Stephen Hemminger <shemminger@linux-foundation.org>
2007-03-06 13:03:19 -08:00
Mike Frysinger
95dd595049 do not ignore build failures in subdirs of iproute2
if a file fails to compile in a subdir of iproute2 fails (say "tunnel.c" in
the "ip" dir), the top level makefile does not abort:
 all: Config
    @for i in $(SUBDIRS); \
    do $(MAKE) $(MFLAGS) -C $$i; done

the attached patch inserts a 'set -e' so that if the $(MAKE) fails, the all
target fails as well
-mike
2007-03-05 17:50:49 -08:00
Stephen Hemminger
ae665a522b Remove trailing whitespace
Go through source files and remove all trailing whitespace

Signed-off-by: Stephen Hemminger <shemminger@osdl.org>
2006-12-05 10:10:22 -08:00
shemminger
6d4662d4f7 From: Pablo Neira
Hi jamal,

I found some spare time to play around a bit more with you ipt action stuff.

I've tested the patch attached with the testcase here below. It works
fine here. It fixes broken target option checkings (final_check) and a
leak in the merge_options function. I've killed copy_options since I
didn't find any reason why we need it.

--- test.sh ---
tc qdisc del dev wlan0 ingress
tc qdisc add dev wlan0 ingress
tc filter add dev wlan0 parent ffff: protocol ip prio 6 u32 \
match ip src 192.168.0.2/32 flowid 1:16 \
action ipt -j TOS --set-tos Maximize-Reliability
sleep 3
tc -s filter ls dev wlan0 parent ffff:
--- end of test.sh ---

Results:

tablename: mangle hook: NF_IP_PRE_ROUTING
         target: TOS set Maximize-Reliability  index 0
filter protocol ip pref 6 u32
filter protocol ip pref 6 u32 fh 800: ht divisor 1
filter protocol ip pref 6 u32 fh 800::800 order 2048 key ht 800 bkt 0
flowid 1:16
   match c0a80002/ffffffff at 12
         action order 1: tablename: mangle  hook: NF_IP_PRE_ROUTING
         target TOS set Maximize-Reliability
         index 18 ref 1 bind 1 installed 3 sec used 0 sec
         Action statistics:
         Sent 725 bytes 7 pkt (dropped 0, overlimits 0 requeues 0)
         rate 0bit 0pps backlog 0b 0p requeues 0

Now, check if options passed to the target are correct.

# tc filter add dev wlan0 parent ffff: protocol ip prio 6 u32 \
match ip dst 192.168.0.2/32 flowid 1:16 \
action ipt -j TOS --set-tos
                             ^^^
                         missing parameter

ipt: option `--set-tos' requires an argument
tc-ipt v0.1: TOS target: Parameter --set-tos is required
Try `tc-ipt -h' or 'tc-ipt --help' for more information.

btw, how's your schedule ? did you finally get spare time to come to the
netfilter workshop in seville ?

bye,
Pablo
2005-06-23 17:36:38 +00:00
net[shemminger]!shemminger
894b1c6687 Import patch p_mipt
(Logical change 1.180)
2005-03-30 18:19:55 +00:00
osdl.net!shemminger
65840e27ba put register_target in and get rid of code that ease
duplicated then marked with if 0

(Logical change 1.156)
2005-03-10 20:21:48 +00:00
2!tgraf
7893400077 Use parse_rtattr_nested
(Logical change 1.129)
2005-01-18 22:11:58 +00:00
2!tgraf
fc78a8e98d Use NLMSG_TAIL
(Logical change 1.127)
2005-01-18 01:24:18 +00:00
net[shemminger]!shemminger
1ffd7fd23e Import patch iproute2.110
(Logical change 1.112)
2005-01-17 23:26:23 +00:00
net[shemminger]!shemminger
3e1d2ea6ab Initial revision 2005-01-17 23:26:23 +00:00