1. 14 12月, 2016 1 次提交
  2. 04 12月, 2016 1 次提交
    • A
      netlink: 2-clause nla_ok() · 4f7df337
      Alexey Dobriyan 提交于
      nla_ok() consists of 3 clauses:
      
      	1) int rem >= (int)sizeof(struct nlattr)
      
      	2) u16 nla_len >= sizeof(struct nlattr)
      
      	3) u16 nla_len <= int rem
      
      The statement is that clause (1) is redundant.
      
      What it does is ensuring that "rem" is a positive number,
      so that in clause (3) positive number will be compared to positive number
      with no problems.
      
      However, "u16" fully fits into "int" and integers do not change value
      when upcasting even to signed type. Negative integers will be rejected
      by clause (3) just fine. Small positive integers will be rejected
      by transitivity of comparison operator.
      
      NOTE: all of the above DOES NOT apply to nlmsg_ok() where ->nlmsg_len is
      u32(!), so 3 clauses AND A CAST TO INT are necessary.
      
      Obligatory space savings report: -1.6 KB
      
      	$ ./scripts/bloat-o-meter ../vmlinux-000* ../vmlinux-001*
      	add/remove: 0/0 grow/shrink: 3/63 up/down: 35/-1692 (-1657)
      	function                                     old     new   delta
      	validate_scan_freqs                          142     155     +13
      	tcf_em_tree_validate                         867     879     +12
      	dcbnl_ieee_del                               328     338     +10
      	netlbl_cipsov4_add_common.isra               218     215      -3
      		...
      	ovs_nla_put_actions                          888     806     -82
      	netlbl_cipsov4_add_std                      1648    1566     -82
      	nl80211_parse_sched_scan                    2889    2780    -109
      	ip_tun_from_nlattr                          3086    2945    -141
      Signed-off-by: NAlexey Dobriyan <adobriyan@gmail.com>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      4f7df337
  3. 20 11月, 2016 1 次提交
    • A
      netlink: use "unsigned int" in nla_next() · 3b2c75d3
      Alexey Dobriyan 提交于
      ->nla_len is unsigned entity (it's length after all) and u16,
      thus it can't overflow when being aligned into int/unsigned int.
      
      (nlmsg_next has the same code, but I didn't yet convince myself
      it is correct to do so).
      
      There is pointer arithmetic in this function and offset being
      unsigned is better:
      
      	add/remove: 0/0 grow/shrink: 1/64 up/down: 5/-309 (-304)
      	function                                     old     new   delta
      	nl80211_set_wiphy                           1444    1449      +5
      	team_nl_cmd_options_set                      997     995      -2
      	tcf_em_tree_validate                         872     870      -2
      	switchdev_port_bridge_setlink                352     350      -2
      	switchdev_port_br_afspec                     312     310      -2
      	rtm_to_fib_config                            428     426      -2
      	qla4xxx_sysfs_ddb_set_param                 2193    2191      -2
      	qla4xxx_iface_set_param                     4470    4468      -2
      	ovs_nla_free_flow_actions                    152     150      -2
      	output_userspace                             518     516      -2
      		...
      	nl80211_set_reg                              654     649      -5
      	validate_scan_freqs                          148     142      -6
      	validate_linkmsg                             288     282      -6
      	nl80211_parse_connkeys                       489     483      -6
      	nlattr_set                                   231     224      -7
      	nf_tables_delsetelem                         267     260      -7
      	do_setlink                                  3416    3408      -8
      	netlbl_cipsov4_add_std                      1672    1659     -13
      	nl80211_parse_sched_scan                    2902    2888     -14
      	nl80211_trigger_scan                        1738    1720     -18
      	do_execute_actions                          2821    2738     -83
      	Total: Before=154865355, After=154865051, chg -0.00%
      Signed-off-by: NAlexey Dobriyan <adobriyan@gmail.com>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      3b2c75d3
  4. 30 10月, 2016 1 次提交
  5. 17 5月, 2016 1 次提交
  6. 24 4月, 2016 6 次提交
  7. 22 4月, 2016 1 次提交
  8. 21 4月, 2016 1 次提交
  9. 20 4月, 2016 2 次提交
  10. 30 9月, 2015 1 次提交
  11. 01 4月, 2015 2 次提交
  12. 18 1月, 2015 1 次提交
    • J
      netlink: make nlmsg_end() and genlmsg_end() void · 053c095a
      Johannes Berg 提交于
      Contrary to common expectations for an "int" return, these functions
      return only a positive value -- if used correctly they cannot even
      return 0 because the message header will necessarily be in the skb.
      
      This makes the very common pattern of
      
        if (genlmsg_end(...) < 0) { ... }
      
      be a whole bunch of dead code. Many places also simply do
      
        return nlmsg_end(...);
      
      and the caller is expected to deal with it.
      
      This also commonly (at least for me) causes errors, because it is very
      common to write
      
        if (my_function(...))
          /* error condition */
      
      and if my_function() does "return nlmsg_end()" this is of course wrong.
      
      Additionally, there's not a single place in the kernel that actually
      needs the message length returned, and if anyone needs it later then
      it'll be very easy to just use skb->len there.
      
      Remove this, and make the functions void. This removes a bunch of dead
      code as described above. The patch adds lines because I did
      
      -	return nlmsg_end(...);
      +	nlmsg_end(...);
      +	return 0;
      
      I could have preserved all the function's return values by returning
      skb->len, but instead I've audited all the places calling the affected
      functions and found that none cared. A few places actually compared
      the return value with <= 0 in dump functionality, but that could just
      be changed to < 0 with no change in behaviour, so I opted for the more
      efficient version.
      
      One instance of the error I've made numerous times now is also present
      in net/phonet/pn_netlink.c in the route_dumpit() function - it didn't
      check for <0 or <=0 and thus broke out of the loop every single time.
      I've preserved this since it will (I think) have caused the messages to
      userspace to be formatted differently with just a single message for
      every SKB returned to userspace. It's possible that this isn't needed
      for the tools that actually use this, but I don't even know what they
      are so couldn't test that changing this behaviour would be acceptable.
      Signed-off-by: NJohannes Berg <johannes.berg@intel.com>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      053c095a
  13. 06 1月, 2015 1 次提交
  14. 29 10月, 2014 1 次提交
  15. 17 10月, 2014 1 次提交
  16. 29 7月, 2014 1 次提交
  17. 22 9月, 2013 1 次提交
  18. 11 9月, 2012 1 次提交
  19. 04 8月, 2012 1 次提交
  20. 02 4月, 2012 4 次提交
  21. 31 1月, 2012 1 次提交
  22. 05 11月, 2011 1 次提交
  23. 23 6月, 2011 1 次提交
    • J
      netlink: advertise incomplete dumps · 670dc283
      Johannes Berg 提交于
      Consider the following situation:
       * a dump that would show 8 entries, four in the first
         round, and four in the second
       * between the first and second rounds, 6 entries are
         removed
       * now the second round will not show any entry, and
         even if there is a sequence/generation counter the
         application will not know
      
      To solve this problem, add a new flag NLM_F_DUMP_INTR
      to the netlink header that indicates the dump wasn't
      consistent, this flag can also be set on the MSG_DONE
      message that terminates the dump, and as such above
      situation can be detected.
      
      To achieve this, add a sequence counter to the netlink
      callback struct. Of course, netlink code still needs
      to use this new functionality. The correct way to do
      that is to always set cb->seq when a dumpit callback
      is invoked and call nl_dump_check_consistent() for
      each new message. The core code will also call this
      function for the final MSG_DONE message.
      
      To make it usable with generic netlink, a new function
      genlmsg_nlhdr() is needed to obtain the netlink header
      from the genetlink user header.
      Signed-off-by: NJohannes Berg <johannes.berg@intel.com>
      Acked-by: NDavid S. Miller <davem@davemloft.net>
      Signed-off-by: NJohn W. Linville <linville@tuxdriver.com>
      670dc283
  24. 10 5月, 2011 1 次提交
  25. 01 2月, 2011 1 次提交
  26. 17 11月, 2010 1 次提交
  27. 05 11月, 2010 1 次提交
  28. 24 6月, 2010 1 次提交
  29. 20 3月, 2010 1 次提交
  30. 19 2月, 2010 1 次提交