24 Aug, 2018

1 commit

  • [ Upstream commit b5685d2687d6612adf5eac519eb7008f74dfd1ec ]

    A reference for the best gateway is taken when the list of gateways in the
    mesh is sent via netlink. This is necessary to check whether the currently
    dumped entry is the currently selected gateway or not. This information is
    then transferred as flag BATADV_ATTR_FLAG_BEST.

    After the comparison of the current entry is done,
    batadv_iv_gw_dump_entry() has to decrease the reference counter again.
    Otherwise the reference will be held and thus prevents a proper shutdown of
    the batman-adv interfaces (and some of the interfaces enslaved in it).

    Fixes: efb766af06e3 ("batman-adv: add B.A.T.M.A.N. IV bat_gw_dump implementations")
    Reported-by: Andreas Ziegler
    Tested-by: Andreas Ziegler
    Signed-off-by: Sven Eckelmann
    Acked-by: Marek Lindner
    Signed-off-by: Simon Wunderlich
    Signed-off-by: Sasha Levin
    Signed-off-by: Greg Kroah-Hartman

    Sven Eckelmann
     

30 May, 2018

1 commit

  • [ Upstream commit 10d570284258a30dc104c50787c5289ec49f3d23 ]

    The function batadv_iv_gw_dump stops the processing loop when
    batadv_iv_gw_dump_entry returns a non-0 return code. This should only
    happen when the buffer is full. Otherwise, an empty message may be
    returned by batadv_gw_dump. This empty message will then stop the netlink
    dumping of gateway entries. At worst, not a single entry is returned to
    userspace even when plenty of possible gateways exist.

    Fixes: efb766af06e3 ("batman-adv: add B.A.T.M.A.N. IV bat_gw_dump implementations")
    Signed-off-by: Sven Eckelmann
    Signed-off-by: Simon Wunderlich
    Signed-off-by: Sasha Levin
    Signed-off-by: Greg Kroah-Hartman

    Sven Eckelmann
     

29 Jul, 2017

2 commits


16 Jun, 2017

1 commit

  • A common pattern with skb_put() is to just want to memcpy()
    some data into the new space, introduce skb_put_data() for
    this.

    An spatch similar to the one for skb_put_zero() converts many
    of the places using it:

    @@
    identifier p, p2;
    expression len, skb, data;
    type t, t2;
    @@
    (
    -p = skb_put(skb, len);
    +p = skb_put_data(skb, data, len);
    |
    -p = (t)skb_put(skb, len);
    +p = skb_put_data(skb, data, len);
    )
    (
    p2 = (t2)p;
    -memcpy(p2, data, len);
    |
    -memcpy(p, data, len);
    )

    @@
    type t, t2;
    identifier p, p2;
    expression skb, data;
    @@
    t *p;
    ...
    (
    -p = skb_put(skb, sizeof(t));
    +p = skb_put_data(skb, data, sizeof(t));
    |
    -p = (t *)skb_put(skb, sizeof(t));
    +p = skb_put_data(skb, data, sizeof(t));
    )
    (
    p2 = (t2)p;
    -memcpy(p2, data, sizeof(*p));
    |
    -memcpy(p, data, sizeof(*p));
    )

    @@
    expression skb, len, data;
    @@
    -memcpy(skb_put(skb, len), data, len);
    +skb_put_data(skb, data, len);

    (again, manually post-processed to retain some comments)

    Reviewed-by: Stephen Hemminger
    Signed-off-by: Johannes Berg
    Signed-off-by: David S. Miller

    Johannes Berg
     

23 May, 2017

2 commits


07 Apr, 2017

1 commit

  • Simon Wunderlich says:

    ====================
    This feature/cleanup patchset includes the following patches:

    - bump version strings, by Simon Wunderlich

    - Code and Style cleanups, by Sven Eckelmann (5 patches)

    - Remove an unneccessary memset, by Tobias Klauser

    - DAT and BLA optimizations for various corner cases, by Andreas Pape
    (5 patches)

    - forward/rebroadcast packet restructuring, by Linus Luessing
    (2 patches)

    - ethtool cleanup and remove unncessary code, by Sven Eckelmann
    (4 patches)

    - use net_device_stats from net_device instead of private copy,
    by Tobias Klauser
    ====================

    Signed-off-by: David S. Miller

    David S. Miller
     

26 Mar, 2017

1 commit


17 Mar, 2017

1 commit


05 Mar, 2017

1 commit

  • The gateway selection class variable is shared between different algorithm
    versions. But the interpretation of the content is algorithm specific. The
    initialization is therefore also algorithm specific.

    But this was implemented incorrectly and the initialization for BATMAN_V
    always overwrote the value previously written for BATMAN_IV. This could
    only be avoided when BATMAN_V was disabled during compile time.

    Using a special batadv_algo hook for this initialization avoids this
    problem.

    Fixes: 50164d8f500f ("batman-adv: B.A.T.M.A.N. V - implement GW selection logic")
    Signed-off-by: Sven Eckelmann
    Signed-off-by: Simon Wunderlich

    Sven Eckelmann
     

26 Jan, 2017

1 commit


09 Nov, 2016

3 commits

  • In rare cases during shutdown the following general protection fault can
    happen:

    general protection fault: 0000 [#1] SMP
    Modules linked in: batman_adv(O-) [...]
    CPU: 3 PID: 1714 Comm: rmmod Tainted: G O 4.6.0-rc6+ #1
    [...]
    Call Trace:
    [] batadv_hardif_disable_interface+0x29a/0x3a6 [batman_adv]
    [] batadv_softif_destroy_netlink+0x4b/0xa4 [batman_adv]
    [] __rtnl_link_unregister+0x48/0x92
    [] rtnl_link_unregister+0xc1/0xdb
    [] ? bit_waitqueue+0x87/0x87
    [] batadv_exit+0x1a/0xf48 [batman_adv]
    [] SyS_delete_module+0x136/0x1b0
    [] entry_SYSCALL_64_fastpath+0x18/0xa8
    [] ? trace_hardirqs_off_caller+0x37/0xa6
    Code: 89 f7 e8 21 bd 0d e1 4d 85 e4 75 0e 31 f6 48 c7 c7 50 d7 3b a0 e8 50 16 f2 e0 49 8b 9c 24 28 01 00 00 48 85 db 0f 84 b2 00 00 00 8b 03 4d 85 ed 48 89 45 c8 74 09 4c 39 ab f8 00 00 00 75 1c
    RIP [] batadv_purge_outstanding_packets+0x1c8/0x291 [batman_adv]
    RSP
    ---[ end trace 803b9bdc6a4a952b ]---
    Kernel panic - not syncing: Fatal exception in interrupt
    Kernel Offset: disabled
    ---[ end Kernel panic - not syncing: Fatal exception in interrupt

    It does not happen often, but may potentially happen when frequently
    shutting down and reinitializing an interface. With some carefully
    placed msleep()s/mdelay()s it can be reproduced easily.

    The issue is, that on interface removal, any still running worker thread
    of a forwarding packet will race with the interface purging routine to
    free a forwarding packet. Temporarily giving up a spin-lock to be able
    to sleep in the purging routine is not safe.

    Furthermore, there is a potential general protection fault not just for
    the purging side shown above, but also on the worker side: Temporarily
    removing a forw_packet from the according forw_{bcast,bat}_list will make
    it impossible for the purging routine to catch and cancel it.

    # How this patch tries to fix it:

    With this patch we split the queue purging into three steps: Step 1),
    removing forward packets from the queue of an interface and by that
    claim it as our responsibility to free.

    Step 2), we are either lucky to cancel a pending worker before it starts
    to run. Or if it is already running, we wait and let it do its thing,
    except two things:

    Through the claiming in step 1) we prevent workers from a) re-arming
    themselves. And b) prevent workers from freeing packets which we still
    hold in the interface purging routine.

    Finally, step 3, we are sure that no forwarding packets are pending or
    even running anymore on the interface to remove. We can then safely free
    the claimed forwarding packets.

    Signed-off-by: Linus Lüssing
    Signed-off-by: Sven Eckelmann
    Signed-off-by: Simon Wunderlich

    Linus Lüssing
     
  • batman-adv is requiring the type of wifi device in different contexts. Some
    of them can take the rtnl semaphore and some of them already have the
    semaphore taken. But even others don't allow that the semaphore will be
    taken.

    The data has to be retrieved when the hardif is added to batman-adv because
    some of the wifi information for an hardif will only be available with rtnl
    lock. It can then be cached in the batadv_hard_iface and the functions
    is_wifi_netdev and is_cfg80211_netdev can just compare the correct bits
    without imposing extra locking requirements.

    Signed-off-by: Sven Eckelmann
    Signed-off-by: Simon Wunderlich

    Sven Eckelmann
     
  • Receiving functions in Linux consume the supplied skbuff. Doing the same in
    the batadv_rx_handler functions makes the behavior more similar to the rest
    of the Linux network code.

    Signed-off-by: Sven Eckelmann
    Signed-off-by: Simon Wunderlich

    Sven Eckelmann
     

30 Oct, 2016

1 commit

  • kfree_skb assumes that an skb is dropped after an failure and notes that.
    consume_skb should be used in non-failure situations. Such information is
    important for dropmonitor netlink which tells how many packets were dropped
    and where this drop happened.

    Signed-off-by: Sven Eckelmann
    Signed-off-by: Simon Wunderlich

    Sven Eckelmann
     

19 Oct, 2016

1 commit


09 Aug, 2016

8 commits

  • The files provided by batman-adv via debugfs are currently converted to
    netlink. Tools which are not yet converted to use the netlink interface may
    still rely on the old debugfs files. But systems which already upgraded
    their tools can save some space by disabling this feature. The default
    configuration of batman-adv on amd64 can reduce the size of the module by
    around 11% when this feature is disabled.

    $ size net/batman-adv/batman-adv.ko*
    text data bss dec hex filename
    150507 10395 4160 165062 284c6 net/batman-adv/batman-adv.ko.y
    137106 7099 2112 146317 23b8d net/batman-adv/batman-adv.ko.n

    Signed-off-by: Sven Eckelmann
    Signed-off-by: Marek Lindner
    Signed-off-by: Simon Wunderlich

    Sven Eckelmann
     
  • It is hard to understand why the refcnt is increased when it isn't done
    near the actual place the new reference is used. So using kref_get right
    before the place which requires the reference and in the same function
    helps to avoid accidental problems caused by incorrect reference counting.

    Signed-off-by: Sven Eckelmann
    Signed-off-by: Marek Lindner
    Signed-off-by: Simon Wunderlich

    Sven Eckelmann
     
  • Dump the list of gateways via the netlink socket.

    Signed-off-by: Andrew Lunn
    [sven.eckelmann@open-mesh.com: integrate in batadv_algo_ops]
    Signed-off-by: Sven Eckelmann
    Signed-off-by: Simon Wunderlich
    Signed-off-by: Marek Lindner

    Andrew Lunn
     
  • Signed-off-by: Matthias Schiffer
    Signed-off-by: Andrew Lunn
    [sven.eckelmann@open-mesh.com: Fix function parameter alignments,
    add policy for attributes, fix includes, fix algo_ops integration]
    Signed-off-by: Sven Eckelmann
    Signed-off-by: Simon Wunderlich
    Signed-off-by: Marek Lindner

    Matthias Schiffer
     
  • This patch abstracts the forward packet creation into the new function
    batadv_forw_packet_alloc().

    The queue counting and interface reference counters are now handled
    internally within batadv_forw_packet_alloc() and its
    batadv_forw_packet_free() counterpart. This should reduce the risk of
    having reference/queue counting bugs again and should increase
    code readibility.

    Signed-off-by: Linus Lüssing
    Signed-off-by: Marek Lindner
    Signed-off-by: Sven Eckelmann
    Signed-off-by: Simon Wunderlich

    Linus Lüssing
     
  • The difference between tq1 and tq2 are calculated the same way in two
    separate functions.

    This patch moves the common code to a separate function
    'batadv_iv_ogm_neigh_diff' which handles everything necessary. The other
    two functions can then handle errors and use the difference directly.

    Signed-off-by: Markus Pargmann
    [sven@narfation.org: rebased on current version, initialize return variable
    in batadv_iv_ogm_neigh_diff, add kerneldoc, convert to bool return type]
    Signed-off-by: Sven Eckelmann
    Signed-off-by: Marek Lindner
    Signed-off-by: Simon Wunderlich

    Markus Pargmann
     
  • Each routing protocol may have its own specific logic about
    gateway election which is potentially based on the metric being
    used.

    Create two GW specific API functions and move the current election
    logic in the B.A.T.M.A.N. IV specific code.

    Signed-off-by: Antonio Quartulli
    Signed-off-by: Sven Eckelmann
    Signed-off-by: Marek Lindner
    Signed-off-by: Simon Wunderlich

    Antonio Quartulli
     
  • Fixes: ef0a937f7a14 ("batman-adv: consider outgoing interface in OGM sending")
    Signed-off-by: Linus Lüssing
    Signed-off-by: Marek Lindner
    Signed-off-by: Sven Eckelmann
    Signed-off-by: Simon Wunderlich

    Linus Lüssing
     

04 Jul, 2016

1 commit

  • The routing API data structure contains several function
    pointers that can easily be grouped together based on the
    component they work with.

    Split the API in subobjects in order to improve definition readability.

    At the same time, remove the "bat_" prefix from the API object and
    its fields names. These are batman-adv private structs and there is no
    need to always prepend such prefix, which only makes function invocations
    much much longer.

    Signed-off-by: Antonio Quartulli
    Reviewed-by: Sven Eckelmann
    Signed-off-by: Marek Lindner
    Signed-off-by: Simon Wunderlich

    Antonio Quartulli
     

30 Jun, 2016

6 commits

  • The bat_algo.h had some functions declared which were not part of the
    bat_algo.c file. These are instead stored in bat_v.c and bat_iv_ogm.c. The
    declaration should therefore be also in bat_v.h and bat_iv_ogm,h to make
    them easier to find.

    Signed-off-by: Sven Eckelmann
    Signed-off-by: Marek Lindner
    Signed-off-by: Simon Wunderlich

    Sven Eckelmann
     
  • There are several places in batman-adv which provide logging related
    functions. These should be grouped together in the log.* files to make them
    easier to find.

    Reported-by: Markus Pargmann
    Signed-off-by: Sven Eckelmann
    Signed-off-by: Marek Lindner
    Signed-off-by: Simon Wunderlich

    Sven Eckelmann
     
  • The tvlv functionality in main.c is mostly unrelated to the rest of the
    content. It still takes up a large portion of this source file (~45%, 588
    lines). Moving it to a separate file makes it better visible as a main
    component of the batman-adv implementation and hides it less in the other
    helper functions in main.c

    Signed-off-by: Markus Pargmann
    [sven@narfation.org: fix conflicts with current version, fix includes,
    rewrote commit message]
    Signed-off-by: Sven Eckelmann
    Signed-off-by: Marek Lindner
    Signed-off-by: Simon Wunderlich

    Markus Pargmann
     
  • It is easier to detect if a include is already there for a used
    functionality when the includes are ordered. Using an alphabetic order
    together with the grouping in commit 1e2c2a4fe4a5 ("batman-adv: Add
    required includes to all files") makes includes better manageable.

    Signed-off-by: Sven Eckelmann
    Signed-off-by: Marek Lindner
    Signed-off-by: Simon Wunderlich

    Sven Eckelmann
     
  • The ogm_emit and ogm_schedule API calls were rather tight to the
    B.A.T.M.A.N. IV logic and therefore rather difficult to use
    with other algorithm implementations.

    Remove such calls and move the surrounding logic into the
    B.A.T.M.A.N. IV specific code.

    Signed-off-by: Antonio Quartulli
    Signed-off-by: Marek Lindner
    Signed-off-by: Sven Eckelmann
    Signed-off-by: Simon Wunderlich

    Antonio Quartulli
     
  • Signed-off-by: Marek Lindner
    Signed-off-by: Sven Eckelmann
    Signed-off-by: Simon Wunderlich

    Marek Lindner
     

18 May, 2016

2 commits

  • The undefined behavior sanatizer detected an signed integer overflow in a
    setup with near perfect link quality

    UBSAN: Undefined behaviour in net/batman-adv/bat_iv_ogm.c:1246:25
    signed integer overflow:
    8713350 * 255 cannot be represented in type 'int'

    The problems happens because the calculation of mixed unsigned and signed
    integers resulted in an integer multiplication.

    batadv_ogm_packet::tq (u8 255)
    * tq_own (u8 255)
    * tq_asym_penalty (int 134; max 255)
    * tq_iface_penalty (int 255; max 255)

    The tq_iface_penalty, tq_asym_penalty and inv_asym_penalty can just be
    changed to unsigned int because they are not expected to become negative.

    Fixes: c039876892e3 ("batman-adv: add WiFi penalty")
    Signed-off-by: Sven Eckelmann
    Signed-off-by: Marek Lindner
    Signed-off-by: Antonio Quartulli

    Sven Eckelmann
     
  • The function batadv_iv_ogm_orig_add_if allocates new buffers for bcast_own
    and bcast_own_sum. It is expected that these buffers are unchanged in case
    either bcast_own or bcast_own_sum couldn't be resized.

    But the error handling of this function frees the already resized buffer
    for bcast_own when the allocation of the new bcast_own_sum buffer failed.
    This will lead to an invalid memory access when some code will try to
    access bcast_own.

    Instead the resized new bcast_own buffer has to be kept. This will not lead
    to problems because the size of the buffer was only increased and therefore
    no user of the buffer will try to access bytes outside of the new buffer.

    Fixes: d0015fdd3d2c ("batman-adv: provide orig_node routing API")
    Signed-off-by: Sven Eckelmann
    Signed-off-by: Marek Lindner
    Signed-off-by: Antonio Quartulli

    Sven Eckelmann
     

10 May, 2016

3 commits

  • It is easier to understand that the returned value of a specific function
    doesn't have to be 0 when the functions was successful when the actual
    return type is bool. This is especially true when all surrounding functions
    with return type int use negative values to return the error code.

    Reported-by: Nicholas Krause
    Signed-off-by: Sven Eckelmann
    Signed-off-by: Marek Lindner
    Signed-off-by: Antonio Quartulli

    Sven Eckelmann
     
  • The callers of the functions using batadv_hard_iface objects already make
    sure that they hold a valid reference. The subfunctions don't have
    to check whether the reference counter is > 0 because this was checked by
    the callers.

    The kref_get function instead WARNs (with debug information) when the
    reference counter would still be 0. This makes a bug in batman-adv better
    visible because kref_get_unless_zero would have ignored this problem.

    Signed-off-by: Sven Eckelmann
    Signed-off-by: Marek Lindner
    Signed-off-by: Antonio Quartulli

    Sven Eckelmann
     
  • The batadv_hardif_list list is checked in many situations and the items
    in this list are given to specialized functions to modify the routing
    behavior. At the moment each of these called functions has to check
    itself whether the received batadv_hard_iface has a refcount > 0 before
    it can increase the reference counter and use it in other objects.

    This can easily lead to problems because it is not easily visible where
    all callers of a function got the batadv_hard_iface object from and
    whether they already hold a valid reference.

    Checking the reference counter directly before calling a subfunction
    with a pointer from the batadv_hardif_list avoids this problem.

    Signed-off-by: Sven Eckelmann
    Signed-off-by: Marek Lindner
    Signed-off-by: Antonio Quartulli

    Sven Eckelmann
     

04 May, 2016

2 commits

  • batadv_iv_ogm_orig_del_if handles two different buffers bcast_own and
    bcast_own_sum which should be resized. The error handling two for
    allocating these buffers causes the complexity of this function. This can
    be avoided completely when the function is split into a main function
    handling the locking, freeing and call of the subfunctions.

    The subfunction can then independently handle the resize of the buffers.
    This also allows to easily reuse the old buffer (which always is larger) in
    case a smaller buffer could not be allocated without increasing the code
    complexity.

    Signed-off-by: Sven Eckelmann
    Signed-off-by: Marek Lindner
    Signed-off-by: Antonio Quartulli

    Sven Eckelmann
     
  • Use a static string when showing table headers rather then
    a nonsense parametric one with fixed arguments.

    It is easier to grep and it does not need to be recomputed
    at runtime each time.

    Reported-by: Joe Perches
    Signed-off-by: Antonio Quartulli
    [sven@narfation.org: fix conflicts with current version]
    Signed-off-by: Sven Eckelmann
    Signed-off-by: Marek Lindner

    Antonio Quartulli
     

29 Feb, 2016

1 commit

  • To enable ELP to send probing packets over wireless links
    only if needed, batman-adv must keep track of the last time
    it sent a unicast packet towards every neighbour.

    For this purpose a 2 main changes are introduced:
    1) a new member of the elp_neigh_node structure stores the
    last time a unicast packet was sent towards this neighbour;
    2) a wrapper function for sending unicast packets is
    implemented. This function will simply update the member
    describe din point 1) and then forward the packet to the
    real sending routine.

    Point 2) implies that any code-path leading to a unicast
    sending now has to use the new wrapper.

    Signed-off-by: Antonio Quartulli
    Signed-off-by: Marek Lindner

    Antonio Quartulli