Commit Graph

59 Commits

Author SHA1 Message Date
Eyal Birger
f33a871b80 ip xfrm: policy: support policies with IF_ID in get/delete/deleteall
The XFRMA_IF_ID attribute is set in policies for them to be
associated with an XFRM interface (4.19+).

Add support for getting/deleting policies with this attribute.

For supporting 'deleteall' the XFRMA_IF_ID attribute needs to be
explicitly copied.

Signed-off-by: Eyal Birger <eyal.birger@gmail.com>
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
2020-07-13 08:51:37 -07:00
Andrea Claudi
38dd041bfe ip-xfrm: Fix help messages
After commit 8589eb4efd ("treewide: refactor help messages") help
messages for xfrm state and policy are broken, printing many times the
same protocol in UPSPEC section:

$ ip xfrm state help
[...]
UPSPEC := proto { { tcp | tcp | tcp | tcp } [ sport PORT ] [ dport PORT ] |
                  { icmp | icmp | icmp } [ type NUMBER ] [ code NUMBER ] |
                  gre [ key { DOTTED-QUAD | NUMBER } ] | PROTO }

This happens because strxf_proto function is non-reentrant and gets called
multiple times in the same fprintf instruction.

This commit fix the issue avoiding calls to strxf_proto() with a constant
param, just hardcoding strings for protocol names.

Fixes: 8589eb4efd ("treewide: refactor help messages")
Signed-off-by: Andrea Claudi <aclaudi@redhat.com>
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
2020-01-29 10:11:14 -08:00
Matteo Croce
8589eb4efd treewide: refactor help messages
Every tool in the iproute2 package have one or more function to show
an help message to the user. Some of these functions print the help
line by line with a series of printf call, e.g. ip/xfrm_state.c does
60 fprintf calls.
If we group all the calls to a single one and just concatenate strings,
we save a lot of libc calls and thus object size. The size difference
of the compiled binaries calculated with bloat-o-meter is:

        ip/ip:
        add/remove: 0/0 grow/shrink: 5/15 up/down: 103/-4796 (-4693)
        Total: Before=672591, After=667898, chg -0.70%
        ip/rtmon:
        add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-54 (-54)
        Total: Before=48879, After=48825, chg -0.11%
        tc/tc:
        add/remove: 0/2 grow/shrink: 31/10 up/down: 882/-6133 (-5251)
        Total: Before=351912, After=346661, chg -1.49%
        bridge/bridge:
        add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-459 (-459)
        Total: Before=70502, After=70043, chg -0.65%
        misc/lnstat:
        add/remove: 0/1 grow/shrink: 1/0 up/down: 48/-486 (-438)
        Total: Before=9960, After=9522, chg -4.40%
        tipc/tipc:
        add/remove: 0/0 grow/shrink: 1/1 up/down: 18/-62 (-44)
        Total: Before=79182, After=79138, chg -0.06%

While at it, indent some strings which were starting at column 0,
and use tabs where possible, to have a consistent style across helps.

Signed-off-by: Matteo Croce <mcroce@redhat.com>
Signed-off-by: David Ahern <dsahern@gmail.com>
2019-05-20 14:35:07 -07:00
Phil Sutter
cd21ae4013 ip-xfrm: Respect family in deleteall and list commands
Allow to limit 'ip xfrm {state|policy} list' output to a certain address
family and to delete all states/policies by family.

Although preferred_family was already set in filters, the filter
function ignored it. To enable filtering despite the lack of other
selectors, filter.use has to be set if family is not AF_UNSPEC.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
2019-05-06 13:32:44 -07:00
Eyal Birger
aed63ae1ac ip xfrm: support setting/printing XFRMA_IF_ID attribute in states/policies
The XFRMA_IF_ID attribute is set in policies/states for them to be
associated with an XFRM interface (4.19+).

Add support for setting / displaying this attribute.

Note that 0 is a valid value therefore set XFRMA_IF_ID if any value
was provided in command line.

Tested-by: Antony Antony <antony@phenome.org>
Signed-off-by: Eyal Birger <eyal.birger@gmail.com>
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
2019-04-11 15:26:43 -07:00
David Ahern
cd554f2c2f Tree wide: Drop sockaddr_nl arg
No function, filter, or print function uses the sockaddr_nl arg,
so just drop it.

Signed-off-by: David Ahern <dsahern@gmail.com>
Acked-by: Stephen Hemminger <stephen@networkplumber.org>
2018-10-22 09:43:48 -07:00
Stephen Hemminger
b158c1790f Merge branch 'master' into net-next 2017-11-09 09:45:17 +09:00
Thomas Egerer
0c7d651b38 xfrm_{state, policy}: Allow to deleteall polices/states with marks
Using 'ip deleteall' with policies that have marks, fails unless you
eplicitely specify the mark values. This is very uncomfortable when
bulk-deleting policies and states. With this patch all relevant states
and policies are wiped by 'ip deleteall' regardless of their mark
values.

Signed-off-by: Thomas Egerer <thomas.egerer@secunet.com>
2017-11-07 11:12:30 +09:00
Thomas Egerer
5474d440b8 xfrm_policy: Do not attempt to deleteall a socket policy
Socket polices are added to a socket using setsockopt(2). They cannot be
deleted by iproute2. The attempt to delete them causes an error
(EINVAL).
To avoid this unnecessary error message all socket policies are skipped
in xfrm_policy_keep.

Signed-off-by: Thomas Egerer <thomas.egerer@secunet.com>
2017-11-07 11:12:30 +09:00
Thomas Egerer
20e4840a0a xfrm_policy: Add filter option for socket policies
Listing policies on systems with a lot of socket policies can be
confusing due to the number of returned polices. Even if socket polices
are not of interest, they cannot be filtered. This patch adds an option
to filter all socket policies from the output.

Signed-off-by: Thomas Egerer <thomas.egerer@secunet.com>
2017-11-07 11:12:30 +09:00
Hangbin Liu
86bf43c7c2 lib/libnetlink: update rtnl_talk to support malloc buff at run time
This is an update for 460c03f3f3 ("iplink: double the buffer size also in
iplink_get()"). After update, we will not need to double the buffer size
every time when VFs number increased.

With call like rtnl_talk(&rth, &req.n, NULL, 0), we can simply remove the
length parameter.

With call like rtnl_talk(&rth, nlh, nlh, sizeof(req), I add a new variable
answer to avoid overwrite data in nlh, because it may has more info after
nlh. also this will avoid nlh buffer not enough issue.

We need to free answer after using.

Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
Signed-off-by: Phil Sutter <phil@nwl.cc>
2017-10-26 12:29:29 +02:00
Stephen Hemminger
9f1370c0e5 netlink route attribute cleanup
Use the new helper functions rta_getattr_u* instead of direct
cast of RTA_DATA().  Where RTA_DATA() is a structure, then remove
the unnecessary cast since RTA_DATA() is void *

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
2017-02-24 08:56:38 -08:00
Alexander Heinlein
d5eb0564da ip/xfrm: Fix deleteall when having many policies installed
Fix "Policy buffer overflow" when trying to use deleteall with many
policies installed.

Signed-off-by: Alexander Heinlein <alexander.heinlein@secunet.com>
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
2017-01-20 09:21:02 -08:00
Phil Sutter
d17b136f7d Use C99 style initializers everywhere
This big patch was compiled by vimgrepping for memset calls and changing
to C99 initializer if applicable. One notable exception is the
initialization of union bpf_attr in tc/tc_bpf.c: changing it would break
for older gcc versions (at least <=3.4.6).

Calls to memset for struct rtattr pointer fields for parse_rtattr*()
were just dropped since they are not needed.

The changes here allowed the compiler to discover some unused variables,
so get rid of them, too.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Acked-by: David Ahern <dsa@cumulusnetworks.com>
2016-07-20 12:05:24 -07:00
Stephen Hemminger
56f5daac98 ip: code cleanup
Run all the ip code through checkpatch and have it fix the obvious stuff.
2016-03-21 11:52:19 -07:00
Zhang Shengju
0dc2e22978 xfrm: remove duplicated include
Remove dupldated include for <linux/xfrm.h>, since it's already
included by 'xfrm.h'.

Signed-off-by: Zhang Shengju <zhangshengju@cmss.chinamobile.com>
2015-07-27 14:36:53 -07:00
Stephen Hemminger
c079e121a7 libnetlink: add size argument to rtnl_talk
There have been several instances where response from kernel
has overrun the stack buffer from the caller. Avoid future problems
by passing a size argument.

Also drop the unused peer and group arguments to rtnl_talk.
2015-05-27 13:00:21 -07:00
Nicolas Dichtel
782cf01dc0 ipxfrm: wrong nl msg sent on deleteall cmd
XFRM netlink family is independent from the route netlink family. It's wrong
to call rtnl_wilddump_request(), because it will add a 'struct ifinfomsg' into
the header and the kernel will complain (at least for xfrm state):

netlink: 24 bytes leftover after parsing attributes in process `ip'.

Reported-by: Gregory Hoggarth <Gregory.Hoggarth@alliedtelesis.co.nz>
Signed-off-by: Nicolas Dichtel <nicolas.dichtel@6wind.com>
2015-04-20 10:04:20 -07:00
Christophe Gouault
025fa9dc7a xfrm: add command for configuring SPD hash table
add a new command to configure the SPD hash table:
   ip xfrm policy set [ hthresh4 LBITS RBITS ] [ hthresh6 LBITS RBITS ]

and code to display the SPD hash configuration:
  ip -s -s xfrm policy count

hthresh4: defines minimum local and remote IPv4 prefix lengths of
selectors to hash a policy. If prefix lengths are greater or equal
to the thresholds, then the policy is hashed, otherwise it falls back
in the policy_inexact chained list.

hthresh6: defines minimum local and remote IPv6 prefix lengths of
selectors to hash a policy, otherwise it falls back
in the policy_inexact chained list.

Example:

% ip -s -s xfrm policy count
         SPD IN  0 OUT 0 FWD 0 (Sock: IN 0 OUT 0 FWD 0)
         SPD buckets: count 7 Max 1048576
         SPD IPv4 thresholds: local 32 remote 32
         SPD IPv6 thresholds: local 128 remote 128

% ip xfrm pol set hthresh4 24 16 hthresh6 64 56

% ip -s -s xfrm policy count
         SPD IN  0 OUT 0 FWD 0 (Sock: IN 0 OUT 0 FWD 0)
         SPD buckets: count 7 Max 1048576
         SPD IPv4 thresholds: local 24 remote 16
         SPD IPv6 thresholds: local 64 remote 56

Signed-off-by: Christophe Gouault <christophe.gouault@6wind.com>
2015-04-10 13:21:27 -07:00
Stephen Hemminger
4806867a6c kill spaces before tabs 2014-02-17 10:56:31 -08:00
Stephen Hemminger
4d98ab00de Fix FSF address in file headers 2013-12-06 15:05:07 -08:00
Christophe Gouault
b557416532 xfrm: enable to set non-wildcard mark 0 on SAs and SPs
ip xfrm considers that the user-defined mark is "any" as soon as
(mark.v & mark.m == 0), which prevents from specifying non-wildcard
marks that include the value 0 (typically 0/0xffffffff).

Yet, matching exactly mark 0 is useful for instance to separate
vti policies from global policies.

Always configure the user mark if mark.m != 0.

Signed-off-by: Christophe Gouault <christophe.gouault@6wind.com>
2013-10-09 15:29:05 -07:00
David Ward
e8740e42ec ip/xfrm: Improve error strings
Quotation marks are now used only to indicate literal text on the
command line.

Signed-off-by: David Ward <david.ward@ll.mit.edu>
2013-03-28 14:42:32 -07:00
David Ward
29665f92c7 ip/xfrm: Improve usage text and documentation
Change ALGO-KEY to ALGO-KEYMAT to make it more obvious that the
keying material might need to contain more than just the key (such
as a salt or nonce value).

List the algorithm names that currently exist in the kernel.

Indicate that for IPComp, the Compression Parameter Index (CPI) is
used as the SPI.

Group the list of mode values by transform protocol.

Signed-off-by: David Ward <david.ward@ll.mit.edu>
2013-03-28 14:40:45 -07:00
Stephen Hemminger
d1f28cf181 ip: make local functions static 2013-02-12 11:38:35 -08:00
Stephen Hemminger
cd70f3f522 libnetlink: remove unused junk callback
Both rtnl_talk and rtnl_dump had a callback for handling portions
of netlink message that do not match the correct pid or seq.
But this callback was never used by any part of iproute2 so remove
it.
2011-12-28 10:37:12 -08:00
David Ward
cbec021913 xfrm: Update documentation
The ip(8) man page and the "ip xfrm [ XFRM-OBJECT ] help" command output
are updated to include missing options, fix errors, and improve grammar.
There are no functional changes made.

The documentation for the ip command has many different meanings for the
same formatting symbols (which really needs to be fixed). This patch makes
consistent use of brackets [ ] to indicate optional parameters, pipes | to
mean "OR", braces { } to group things together, and dashes - instead of
underscores _ inside of parameter names. The parameters are listed in the
order in which they are parsed in the source code.

There are several parameters and options that are still not mentioned or
need to be described more thoroughly in the "COMMAND SYNTAX" section of
the ip(8) man page. I would appreciate help from the developers with this.

Signed-off-by: David Ward <david.ward@ll.mit.edu>
2011-07-11 10:12:06 -07:00
Ulrich Weber
c0635644cd iproute2: parse flag XFRM_POLICY_ICMP
parse flag XFRM_POLICY_ICMP

Signed-off-by: Ulrich Weber <uweber@astaro.com>
2011-04-12 14:38:32 -07:00
Joy Latten
e4f054f017 xfrm security context support
Adds security context support to ip xfrm policy.

Signed-off-by: Joy Latten <latten@austin.ibm.com>
2011-02-25 12:45:49 -08:00
Timo Teräs
4a9608e6ae iproute2: support xfrm upper protocol gre key
Similar to tunnel side: accept dotted-quad and number formats.
Use regular number for printing the key.

Signed-off-by: Timo Teräs <timo.teras@iki.fi>
2010-11-30 09:53:23 -08:00
Jamal Hadi Salim
ee675e8714 xfrm: policy by mark
Add support for SP manipulation by mark

Signed-off-by: Jamal Hadi Salim <hadi@cyberus.ca>
2010-03-03 16:37:26 -08:00
Alex Badea
e6e0b60f2a ip xfrm policy: allow different tmpl family
Allow tmpl IP addresses to have a different family than
selector addresses.  This is useful in conjunction with
XFRM_STATE_AF_UNSPEC.

Signed-off-by: Alex Badea <abadea@ixiacom.com>
2010-01-21 10:11:23 -08:00
Stephen Hemminger
f31a37f79d fix problem caused by rtnl_send checks
Some usages of rtnl_send could cause errors (ie flush requests)
others do a listen afterwards.

Signed-off-by: Stephen Hemminger <stephen.hemminger@vyatta.com>
2008-01-31 21:38:58 -08:00
Stephen Hemminger
1fb0a998e1 remove extra newline from perror() calls
perror error adds a newline, so don't split error message
across two lines.
2008-01-26 11:08:31 -08:00
Masahide NAKAMURA
c1fa225324 ip: xfrm: Fix policy and state flags.
o Support policy flag with string format.
  Note that kernel defines only one name "localok" for the flag
  and it has not had any effect currently.
o Support state flag value XFRM_STATE_NOPMTUDISC.
o Fix to show detailed flags value when "-s" option is used.
o Fix minor typo.

Signed-off-by: Masahide NAKAMURA <nakam@linux-ipv6.org>
Signed-off-by: Stephen Hemminger <shemminger@linux-foundation.org>
2007-09-05 12:56:32 +01:00
Masahide NAKAMURA
ed01e39068 ip: xfrm: Clean-up for internal mask to filter.
Remove unused or redundant usage for xfrm_filter.

Signed-off-by: Masahide NAKAMURA <nakam@linux-ipv6.org>
Signed-off-by: Stephen Hemminger <shemminger@linux-foundation.org>
2007-09-05 12:56:17 +01:00
Stephen Hemminger
bdf9e86d72 fix last change
Need to use correct XFRMA_ constants.
Get rid of bogus casts. Fix case where no attribute returned.

Signed-off-by: Stephen Hemminger <shemminger@linux-foundation.org>
2007-06-19 16:24:08 -07:00
jamal
f90c4f4e12 see SPD info
and heres the SPD version ...

cheers,
jamal

[XFRM] see SPD info

i.e instead of something like ip xfrm policy ls | grep -i src | wc -l
do:

ip xfrm policy count
And you get the count; you can also pass -s or -s -s to see more
details

Signed-off-by: Jamal Hadi Salim <hadi@cyberus.ca>
Signed-off-by: Stephen Hemminger <shemminger@linux-foundation.org>
2007-06-19 16:16:07 -07: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
Masahide NAKAMURA
7ea4f5d33d XFRM: Mobile IPv6 route optimization support.
To support Mobile IPv6 RO, the following extension is included:
o Use XFRM_MODE_XXX macro instead of magic number
o New attribute option for all state: source address for
  deleting or getting message
o New attribute options for RO: care-of address, last-used timestamp
  and wild-receive flag

Note:
Flush command like `ip xfrm state flush` is to remove all XFRM state.
It has been effected for IPsec SAD but with this patch it flushes both
IPsec SAD and Mobile IPv6 RO states.
To make only IPsec SA flush, it is recommanded to specify each XFRM
protocol like below:
 `ip x s f proto esp ; ip x s f proto ah ; ip x s f proto comp`

Signed-off-by: Masahide NAKAMURA <nakam@linux-ipv6.org>
Signed-off-by: Stephen Hemminger <shemminger@osdl.org>
2006-12-05 10:03:32 -08:00
Masahide NAKAMURA
972938e9e6 XFRM: sub policy support.
Signed-off-by: Masahide NAKAMURA <nakam@linux-ipv6.org>
Signed-off-by: Stephen Hemminger <shemminger@osdl.org>
2006-12-05 10:03:23 -08:00
Stephen Hemminger
34e099e24f SA and SP in IPSec BEET mode.
Patch which allows for setting SA and SP also for
new IPSec mode BEET, beside tunnel and transport, according to the latest
changes in the kernel you can find at the following link:

Signed-off-by: Diego Beltrami <diego.beltrami@gmail.com>
Signed-off-by: Miika Komu <miika@iki.fi>
Signed-off-by: Stephen Hemminger <shemminger@osdl.org>
2006-10-19 13:15:35 -07:00
Andy Gay
af1b6a41d4 Fix struct alignment with cris architecture
[IPROUTE]: Fix struct alignment with cris architecture

gcc for the cris arch does not pad structures to the next multiple of 4
bytes, as the i386 gcc does.

This causes errors like this when displaying xfrm policies:

# ip x p
!!!Deficit 3, rta_len=300
src 192.168.251.32/29 dst 192.168.251.32/29
        dir in priority 0
!!!Deficit 3, rta_len=180
src 0.0.0.0/0 dst 192.168.251.32/29
        dir in priority 2208
....

Similar errors are seen from ip x s.

This patch fixes the errors when printing. I'm not sure whether we
should worry about other uses of the affected structs, I've not seen any
other bad effects from this though, so hopefully this is enough.

(Thanks to Herbert Xu for pointing out that NLMSG_SPACE is the correct
macro to use here.)

Tested against 2.6.17.6 kernel on i386, and 2.6.16.1 kernel on cris.

Signed-off-by: Andy Gay <andy@andynet.net>
Signed-off-by: Stephen Hemminger <shemminger@osdl.org>
2006-08-11 09:44:36 -07:00
shemminger
669ae748d6 Minor fixes from Masahide for XFRM dynamic keying 2005-11-07 18:39:30 +00:00
shemminger
c595c790a0 Fix XFRM bugs introduced by batching code.
Re-introduces the SA and policy add/del events
2005-11-01 23:03:03 +00:00
shemminger
9bec1a4363 Masahide NAKAMURA <nakam@linux-ipv6.org>
It fixes flush feature for IPsec(ip xfrm).
Jamal gave me comment about it. I've tested it on 2.6.11.7.
Please find the log below, check code and pull it:

bk://bk.skbuff.net:38000/iproute2-xfrm-flush


ChangeSet@1.182, 2005-04-13 21:19:44+09:00, nakam@linux-ipv6.org
  [ip] add "deleteall" command for xfrm;
  "flush" uses kernel's flush interface and
  "deleteall" uses legacy iproute2's flush feature like
  getting-and-deleting-for-each.
2005-06-07 21:58:25 +00:00
shemminger
90f93024a0 Monitor time patch from Masahide NAKAMURA 2005-06-07 21:55:55 +00:00
linux-ipv6.org!nakam
56e8ad38cb split printing policy info function for xfrm common use.
(Logical change 1.175)
2005-03-22 16:13:21 +00:00
12!tgraf
2534613eeb Switch to parse_rtattr and use XFRMA_MAX directly instead of a easly
forgetable magic define

(Logical change 1.129)
2005-01-18 22:11:58 +00:00
net[shemminger]!shemminger
eaa34ee35d Import patch iproute2.117
(Logical change 1.119)
2005-01-17 23:29:39 +00:00