Per interface IPv4 stats (CONFIG_IP_IFSTATS_TABLE)
Subsystems (10)
PATCH 1/1 Per interface IPv4 stats (CONFIG_IP_IFSTATS_TABLE)
This is enhanced from the proposed patch by Igor Maravic in 2011 to support per interface IPv4 stats. The enhancement is mainly adding a kernel configuration option CONFIG_IP_IFSTATS_TABLE.
--- drivers/net/vrf.c | 2 +- include/linux/inetdevice.h | 22 +++++++ include/net/icmp.h | 44 ++++++++++++-- include/net/ip.h | 72 +++++++++++++++++++++-- include/net/ipv6.h | 62 ++++---------------- include/net/netns/mib.h | 3 + include/net/snmp.h | 95 ++++++++++++++++++++++++++++++ net/bridge/br_netfilter_hooks.c | 10 ++-- net/dccp/ipv4.c | 4 +- net/ipv4/Kconfig | 8 +++ net/ipv4/af_inet.c | 7 ++- net/ipv4/datagram.c | 2 +- net/ipv4/devinet.c | 85 ++++++++++++++++++++++++++- net/ipv4/icmp.c | 32 +++++----- net/ipv4/inet_connection_sock.c | 8 ++- net/ipv4/ip_forward.c | 8 +-- net/ipv4/ip_fragment.c | 20 ++++--- net/ipv4/ip_input.c | 29 ++++----- net/ipv4/ip_output.c | 40 ++++++++----- net/ipv4/ipmr.c | 6 +- net/ipv4/ping.c | 9 ++- net/ipv4/proc.c | 126 ++++++++++++++++++++++++++++++++++++++++ net/ipv4/raw.c | 4 +- net/ipv4/route.c | 6 +- net/ipv4/tcp_ipv4.c | 4 +- net/ipv4/udp.c | 4 +- net/l2tp/l2tp_ip.c | 4 +- net/l2tp/l2tp_ip6.c | 2 +- net/mpls/af_mpls.c | 2 +- net/netfilter/ipvs/ip_vs_xmit.c | 2 +- net/sctp/input.c | 2 +- net/sctp/output.c | 2 +- 32 files changed, 570 insertions(+), 156 deletions(-)
drivers/net/vrf.c +1 -1
@@ -592,7 +592,7 @@ static int vrf_output(struct net *net, struct sock *sk, struct sk_buff *skb) {struct net_device *dev =skb_dst (skb)->dev; -IP_UPD_PO_STATS (net,IPSTATS_MIB_OUT , skb->len); +IP_UPD_PO_STATS (net, dev,IPSTATS_MIB_OUT , skb->len); skb->dev = dev; skb->protocol =htons (ETH_P_IP );
include/linux/inetdevice.h +22 -0
@@ -22,6 +22,15 @@ struct ipv4_devconf {#define MC_HASH_SZ_LOG 9 +#ifdef CONFIG_IP_IFSTATS_TABLE +struct ipv4_devstat { +struct proc_dir_entry *proc_dir_entry; + DEFINE_SNMP_STAT(struct ipstats_mib, ip); + DEFINE_SNMP_STAT_ATOMIC(struct icmp_mib_device, icmpdev); + DEFINE_SNMP_STAT_ATOMIC(struct icmpmsg_mib_device, icmpmsgdev); +}; +#endif +struct in_device {struct net_device *dev;refcount_t refcnt;
@@ -45,6 +54,9 @@ struct in_device {struct neigh_parms *arp_parms;struct ipv4_devconf cnf; +#ifdef CONFIG_IP_IFSTATS_TABLE +struct ipv4_devstat stats; +#endif struct rcu_head rcu_head; };
@@ -216,6 +228,16 @@ static inline struct in_device *__in_dev_get_rcu(const struct net_device *dev)return rcu_dereference (dev->ip_ptr); } +#ifdef CONFIG_IP_IFSTATS_TABLE +static inline struct in_device *__in_dev_get_rcu_safely (const struct net_device *dev) +{ +if (likely (dev)) +return rcu_dereference (dev->ip_ptr); +else +return NULL ; +} +#endif +static inline struct in_device *in_dev_get (const struct net_device *dev) {struct in_device *in_dev;
include/net/icmp.h +39 -5
55 lines not on this page · raw message
include/net/ip.h +66 -6
88 lines not on this page · raw message
include/net/ipv6.h +10 -52
81 lines not on this page · raw message
include/net/netns/mib.h +3 -0
@@ -5,6 +5,9 @@#include <net/snmp.h> struct netns_mib { +#ifdef CONFIG_IP_IFSTATS_TABLE +struct proc_dir_entry *proc_net_devsnmp; +#endif DEFINE_SNMP_STAT(struct tcp_mib, tcp_statistics); DEFINE_SNMP_STAT(struct ipstats_mib, ip_statistics); DEFINE_SNMP_STAT(struct linux_mib, net_statistics);
include/net/snmp.h +95 -0
113 lines not on this page · raw message
net/bridge/br_netfilter_hooks.c +5 -5
@@ -218,13 +218,13 @@ static int br_validate_ipv4(struct net *net, struct sk_buff *skb) len =ntohs (iph->tot_len);if (skb->len < len) { -__IP_INC_STATS (net,IPSTATS_MIB_INTRUNCATEDPKTS ); +__IP_INC_STATS (net, skb->dev,IPSTATS_MIB_INTRUNCATEDPKTS ); goto drop; }else if (len < (iph->ihl*4 )) goto inhdr_error;if (pskb_trim_rcsum (skb, len)) { -__IP_INC_STATS (net,IPSTATS_MIB_INDISCARDS ); +__IP_INC_STATS (net, skb->dev,IPSTATS_MIB_INDISCARDS ); goto drop; }
@@ -237,9 +237,9 @@ static int br_validate_ipv4(struct net *net, struct sk_buff *skb)return 0 ; csum_error: -__IP_INC_STATS (net,IPSTATS_MIB_CSUMERRORS ); +__IP_INC_STATS (net, skb->dev,IPSTATS_MIB_CSUMERRORS ); inhdr_error: -__IP_INC_STATS (net,IPSTATS_MIB_INHDRERRORS ); +__IP_INC_STATS (net, skb->dev,IPSTATS_MIB_INHDRERRORS ); drop:return -1 ; }
@@ -691,7 +691,7 @@ br_nf_ip_fragment(struct net *net, struct sock *sk, struct sk_buff *skb,if (unlikely (((iph->frag_off &htons (IP_DF )) && !skb->ignore_df) || (IPCB (skb)->frag_max_size &&IPCB (skb)->frag_max_size > mtu))) { -IP_INC_STATS (net,IPSTATS_MIB_FRAGFAILS ); +IP_INC_STATS (net,skb_dst (skb)->dev,IPSTATS_MIB_FRAGFAILS );kfree_skb (skb);return -EMSGSIZE ; }
net/dccp/ipv4.c +2 -2
@@ -258,7 +258,7 @@ static void dccp_v4_err(struct sk_buff *skb, u32 info) iph->saddr,ntohs (dh->dccph_sport), inet_iif(skb), 0);if (!sk) { -__ICMP_INC_STATS (net,ICMP_MIB_INERRORS ); +__ICMP_INC_STATS (net, skb->dev,ICMP_MIB_INERRORS );return ; }
@@ -468,7 +468,7 @@ static struct dst_entry* dccp_v4_route_skb(struct net *net, struct sock *sk,security_skb_classify_flow (skb,flowi4_to_flowi (&fl4)); rt =ip_route_output_flow (net, &fl4, sk);if (IS_ERR (rt)) { -IP_INC_STATS (net,IPSTATS_MIB_OUTNOROUTES ); +IP_INC_STATS (net,NULL ,IPSTATS_MIB_OUTNOROUTES );return NULL ; }
net/ipv4/Kconfig +8 -0
@@ -52,6 +52,14 @@ config IP_ADVANCED_ROUTER If unsure, say N here. +config IP_IFSTATS_TABLE + def_bool n + depends on IP_ADVANCED_ROUTER + prompt "IP: interface statistics" + help + This option enables per interface statistics for IPv4. Refer to + RFC 4293. + config IP_FIB_TRIE_STATS bool "FIB TRIE statistics" depends on IP_ADVANCED_ROUTER
net/ipv4/af_inet.c +5 -2
@@ -1938,6 +1938,11 @@ static int __init inet_init(void)inet_register_protosw (q);/* +* Init proc fs before initializing devinet +*/ +ipv4_proc_init (); + +/* * Set the ARP module up */
@@ -1984,8 +1989,6 @@ static int __init inet_init(void)if (init_ipv4_mibs ())pr_crit ("%s: Cannot init ipv4 mibs\n" , __func__); -ipv4_proc_init (); -ipfrag_init ();dev_add_pack (&ip_packet_type);
net/ipv4/datagram.c +1 -1
@@ -55,7 +55,7 @@ int __ip4_datagram_connect(struct sock *sk, struct sockaddr *uaddr, int addr_lenif (IS_ERR (rt)) { err =PTR_ERR (rt);if (err == -ENETUNREACH ) -IP_INC_STATS (sock_net (sk),IPSTATS_MIB_OUTNOROUTES ); +IP_INC_STATS (sock_net (sk),NULL ,IPSTATS_MIB_OUTNOROUTES ); goto out; }
net/ipv4/devinet.c +83 -2
119 lines not on this page · raw message
net/ipv4/icmp.c +17 -15
@@ -338,10 +338,10 @@ static bool icmpv4_xrlim_allow(struct net *net, struct rtable *rt,/* * Maintain the counters used in the SNMP statistics for outgoing ICMP */ -void icmp_out_count (struct net *net,unsigned char type) +void icmp_out_count (struct net_device *dev,unsigned char type) { -ICMPMSGOUT_INC_STATS (net, type); -ICMP_INC_STATS (net,ICMP_MIB_OUTMSGS ); +ICMPMSGOUT_INC_STATS (dev_net (dev), dev, type); +ICMP_INC_STATS (dev_net (dev), dev,ICMP_MIB_OUTMSGS ); }/*
@@ -370,13 +370,14 @@ static void icmp_push_reply(struct icmp_bxm *icmp_param, {struct sock *sk;struct sk_buff *skb; +struct net_device *dev = (*rt)->dst.dev; - sk =icmp_sk (dev_net ((*rt)->dst.dev)); + sk =icmp_sk (dev_net (dev));if (ip_append_data (sk, fl4, icmp_glue_bits, icmp_param, icmp_param->data_len+icmp_param->head_len, icmp_param->head_len, ipc, rt,MSG_DONTWAIT ) <0 ) { -__ICMP_INC_STATS (sock_net (sk),ICMP_MIB_OUTERRORS ); +__ICMP_INC_STATS (sock_net (sk), dev,ICMP_MIB_OUTERRORS );ip_flush_pending_frames (sk); }else if ((skb =skb_peek (&sk->sk_write_queue)) !=NULL ) {struct icmphdr *icmph =icmp_hdr (skb);
@@ -760,7 +761,7 @@ static void icmp_socket_deliver(struct sk_buff *skb, u32 info)* avoid additional coding at protocol handlers. */ if (!pskb_may_pull (skb, iph->ihl *4 +8 )) { -__ICMP_INC_STATS (dev_net (skb->dev),ICMP_MIB_INERRORS ); +__ICMP_INC_STATS (dev_net (skb->dev), skb->dev,ICMP_MIB_INERRORS );return ; }
@@ -792,8 +793,9 @@ static bool icmp_unreach(struct sk_buff *skb)struct icmphdr *icmph;struct net *net;u32 info =0 ; +struct net_device *dev =skb_dst (skb)->dev; - net =dev_net (skb_dst (skb)->dev); + net =dev_net (dev);/* * Incomplete header ?
@@ -852,7 +854,7 @@ static bool icmp_unreach(struct sk_buff *skb) info =ntohl (icmph->un.gateway) >>24 ;break ;case ICMP_TIME_EXCEEDED : -__ICMP_INC_STATS (net,ICMP_MIB_INTIMEEXCDS ); +__ICMP_INC_STATS (net, dev,ICMP_MIB_INTIMEEXCDS );if (icmph->code ==ICMP_EXC_FRAGTIME ) goto out;break ;
@@ -890,7 +892,7 @@ static bool icmp_unreach(struct sk_buff *skb) out:return true; out_err: -__ICMP_INC_STATS (net,ICMP_MIB_INERRORS ); +__ICMP_INC_STATS (net, dev,ICMP_MIB_INERRORS );return false; }
@@ -902,7 +904,7 @@ static bool icmp_unreach(struct sk_buff *skb)static bool icmp_redirect (struct sk_buff *skb) {if (skb->len <sizeof (struct iphdr )) { -__ICMP_INC_STATS (dev_net (skb->dev),ICMP_MIB_INERRORS ); +__ICMP_INC_STATS (dev_net (skb->dev), skb->dev,ICMP_MIB_INERRORS );return false; }
@@ -982,7 +984,7 @@ static bool icmp_timestamp(struct sk_buff *skb)return true; out_err: -__ICMP_INC_STATS (dev_net (skb_dst (skb)->dev),ICMP_MIB_INERRORS ); +__ICMP_INC_STATS (dev_net (skb_dst (skb)->dev),skb_dst (skb)->dev,ICMP_MIB_INERRORS );return false; }
@@ -1022,7 +1024,7 @@ int icmp_rcv(struct sk_buff *skb)skb_set_network_header (skb, nh); } -__ICMP_INC_STATS (net,ICMP_MIB_INMSGS ); +__ICMP_INC_STATS (net, skb->dev,ICMP_MIB_INMSGS );if (skb_checksum_simple_validate (skb)) goto csum_error;
@@ -1032,7 +1034,7 @@ int icmp_rcv(struct sk_buff *skb) icmph =icmp_hdr (skb); -ICMPMSGIN_INC_STATS (net, icmph->type); +ICMPMSGIN_INC_STATS (net, skb->dev, icmph->type);/* * 18 is the highest 'known' ICMP type. Anything else is a mystery *
@@ -1078,9 +1080,9 @@ int icmp_rcv(struct sk_buff *skb)kfree_skb (skb);return NET_RX_DROP ; csum_error: -__ICMP_INC_STATS (net,ICMP_MIB_CSUMERRORS ); +__ICMP_INC_STATS (net, skb->dev,ICMP_MIB_CSUMERRORS ); error: -__ICMP_INC_STATS (net,ICMP_MIB_INERRORS ); +__ICMP_INC_STATS (net, skb->dev,ICMP_MIB_INERRORS ); goto drop; }
net/ipv4/inet_connection_sock.c +6 -2
@@ -539,6 +539,7 @@ struct dst_entry *inet_csk_route_req(const struct sock *sk,struct net *net =read_pnet (&ireq->ireq_net);struct ip_options_rcu *opt;struct rtable *rt; +struct net_device *dev =NULL ; opt =ireq_opt_deref (ireq);
@@ -557,9 +558,10 @@ struct dst_entry *inet_csk_route_req(const struct sock *sk,return &rt->dst; route_err: + dev = rt->dst.dev;ip_rt_put (rt); no_route: -__IP_INC_STATS (net,IPSTATS_MIB_OUTNOROUTES ); +__IP_INC_STATS (net, dev,IPSTATS_MIB_OUTNOROUTES );return NULL ; }EXPORT_SYMBOL_GPL (inet_csk_route_req);
@@ -574,6 +576,7 @@ struct dst_entry *inet_csk_route_child_sock(const struct sock *sk,struct ip_options_rcu *opt;struct flowi4 *fl4;struct rtable *rt; +struct net_device *dev =NULL ; opt =rcu_dereference (ireq->ireq_opt); fl4 = &newinet->cork.fl.u.ip4;
@@ -593,9 +596,10 @@ struct dst_entry *inet_csk_route_child_sock(const struct sock *sk,return &rt->dst; route_err: + dev = rt->dst.dev;ip_rt_put (rt); no_route: -__IP_INC_STATS (net,IPSTATS_MIB_OUTNOROUTES ); +__IP_INC_STATS (net, dev,IPSTATS_MIB_OUTNOROUTES );return NULL ; }EXPORT_SYMBOL_GPL (inet_csk_route_child_sock);
net/ipv4/ip_forward.c +4 -4
@@ -66,8 +66,8 @@ static int ip_forward_finish(struct net *net, struct sock *sk, struct sk_buff *s {struct ip_options *opt = &(IPCB (skb)->opt); -__IP_INC_STATS (net,IPSTATS_MIB_OUTFORWDATAGRAMS ); -__IP_ADD_STATS (net,IPSTATS_MIB_OUTOCTETS , skb->len); +__IP_INC_STATS (net,skb_dst (skb)->dev,IPSTATS_MIB_OUTFORWDATAGRAMS ); +__IP_ADD_STATS (net,skb_dst (skb)->dev,IPSTATS_MIB_OUTOCTETS , skb->len);if (unlikely (opt->optlen))ip_forward_options (skb);
@@ -121,7 +121,7 @@ int ip_forward(struct sk_buff *skb)IPCB (skb)->flags |=IPSKB_FORWARDED ; mtu =ip_dst_mtu_maybe_forward (&rt->dst, true);if (ip_exceeds_mtu (skb, mtu)) { -IP_INC_STATS (net,IPSTATS_MIB_FRAGFAILS ); +IP_INC_STATS (net, rt->dst.dev,IPSTATS_MIB_FRAGFAILS );icmp_send (skb,ICMP_DEST_UNREACH ,ICMP_FRAG_NEEDED ,htonl (mtu)); goto drop;
@@ -158,7 +158,7 @@ int ip_forward(struct sk_buff *skb) too_many_hops:/* Tell the sender its packet died... */ -__IP_INC_STATS (net,IPSTATS_MIB_INHDRERRORS ); +__IP_INC_STATS (net,skb_dst (skb)->dev,IPSTATS_MIB_INHDRERRORS );icmp_send (skb,ICMP_TIME_EXCEEDED ,ICMP_EXC_TTL ,0 ); drop:kfree_skb (skb);
net/ipv4/ip_fragment.c +12 -8
@@ -136,6 +136,7 @@ static void ip_expire(struct timer_list *t) {struct inet_frag_queue *frag =from_timer (frag, t, timer);const struct iphdr *iph; +struct net_device *dev;struct sk_buff *head;struct net *net;struct ipq *qp;
@@ -151,16 +152,17 @@ static void ip_expire(struct timer_list *t) goto out;ipq_kill (qp); -__IP_INC_STATS (net,IPSTATS_MIB_REASMFAILS ); + dev =dev_get_by_index_rcu (net, qp->iif); +__IP_INC_STATS (net, dev,IPSTATS_MIB_REASMFAILS ); head = qp->q.fragments; -__IP_INC_STATS (net,IPSTATS_MIB_REASMTIMEOUT ); +__IP_INC_STATS (net, dev,IPSTATS_MIB_REASMTIMEOUT );if (!(qp->q.flags &INET_FRAG_FIRST_IN ) || !head) goto out; - head->dev =dev_get_by_index_rcu (net, qp->iif); + head->dev = dev;if (!head->dev) goto out;
@@ -237,7 +239,9 @@ static int ip_frag_too_far(struct ipq *qp)struct net *net; net = container_of(qp->q.net, struct net, ipv4.frags); -__IP_INC_STATS (net,IPSTATS_MIB_REASMFAILS ); +rcu_read_lock (); +__IP_INC_STATS (net,dev_get_by_index_rcu (net, qp->iif),IPSTATS_MIB_REASMFAILS ); +rcu_read_unlock (); }return rc;
@@ -582,7 +586,7 @@ static int ip_frag_reasm(struct ipq *qp, struct sk_buff *prev,ip_send_check (iph); -__IP_INC_STATS (net,IPSTATS_MIB_REASMOKS ); +__IP_INC_STATS (net, dev,IPSTATS_MIB_REASMOKS ); qp->q.fragments =NULL ; qp->q.fragments_tail =NULL ;return 0 ;
@@ -594,7 +598,7 @@ static int ip_frag_reasm(struct ipq *qp, struct sk_buff *prev, out_oversize:net_info_ratelimited ("Oversized IP packet from %pI4\n" , &qp->q.key.v4.saddr); out_fail: -__IP_INC_STATS (net,IPSTATS_MIB_REASMFAILS ); +__IP_INC_STATS (net, dev,IPSTATS_MIB_REASMFAILS );return err; }
@@ -605,7 +609,7 @@ int ip_defrag(struct net *net, struct sk_buff *skb, u32 user)int vif =l3mdev_master_ifindex_rcu (dev);struct ipq *qp; -__IP_INC_STATS (net,IPSTATS_MIB_REASMREQDS ); +__IP_INC_STATS (net, dev,IPSTATS_MIB_REASMREQDS );skb_orphan (skb);/* Lookup (or create) queue header */
@@ -622,7 +626,7 @@ int ip_defrag(struct net *net, struct sk_buff *skb, u32 user)return ret; } -__IP_INC_STATS (net,IPSTATS_MIB_REASMFAILS ); +__IP_INC_STATS (net, dev,IPSTATS_MIB_REASMFAILS );kfree_skb (skb);return -ENOMEM ; }
net/ipv4/ip_input.c +15 -14
@@ -197,6 +197,7 @@ static int ip_local_deliver_finish(struct net *net, struct sock *sk, struct sk_bint protocol =ip_hdr (skb)->protocol;const struct net_protocol *ipprot;int raw; +struct net_device *dev = skb->dev; resubmit: raw =raw_local_deliver (skb, protocol);
@@ -217,17 +218,17 @@ static int ip_local_deliver_finish(struct net *net, struct sock *sk, struct sk_b protocol = -ret; goto resubmit; } -__IP_INC_STATS (net,IPSTATS_MIB_INDELIVERS ); +__IP_INC_STATS (net, dev,IPSTATS_MIB_INDELIVERS ); }else {if (!raw) {if (xfrm4_policy_check (NULL ,XFRM_POLICY_IN , skb)) { -__IP_INC_STATS (net,IPSTATS_MIB_INUNKNOWNPROTOS ); +__IP_INC_STATS (net, dev,IPSTATS_MIB_INUNKNOWNPROTOS );icmp_send (skb,ICMP_DEST_UNREACH ,ICMP_PROT_UNREACH ,0 ); }kfree_skb (skb); }else { -__IP_INC_STATS (net,IPSTATS_MIB_INDELIVERS ); +__IP_INC_STATS (net, dev,IPSTATS_MIB_INDELIVERS );consume_skb (skb); } }
@@ -272,7 +273,7 @@ static inline bool ip_rcv_options(struct sk_buff *skb)--ANK (980813) */ if (skb_cow (skb,skb_headroom (skb))) { -__IP_INC_STATS (dev_net (dev),IPSTATS_MIB_INDISCARDS ); +__IP_INC_STATS (dev_net (dev), dev,IPSTATS_MIB_INDISCARDS ); goto drop; }
@@ -281,7 +282,7 @@ static inline bool ip_rcv_options(struct sk_buff *skb) opt->optlen = iph->ihl*4 -sizeof (struct iphdr );if (ip_options_compile (dev_net (dev), opt, skb)) { -__IP_INC_STATS (dev_net (dev),IPSTATS_MIB_INHDRERRORS ); +__IP_INC_STATS (dev_net (dev), dev,IPSTATS_MIB_INHDRERRORS ); goto drop; }
@@ -366,9 +367,9 @@ static int ip_rcv_finish(struct net *net, struct sock *sk, struct sk_buff *skb) rt =skb_rtable (skb);if (rt->rt_type ==RTN_MULTICAST ) { -__IP_UPD_PO_STATS (net,IPSTATS_MIB_INMCAST , skb->len); +__IP_UPD_PO_STATS (net, dev,IPSTATS_MIB_INMCAST , skb->len); }else if (rt->rt_type ==RTN_BROADCAST ) { -__IP_UPD_PO_STATS (net,IPSTATS_MIB_INBCAST , skb->len); +__IP_UPD_PO_STATS (net, dev,IPSTATS_MIB_INBCAST , skb->len); }else if (skb->pkt_type ==PACKET_BROADCAST || skb->pkt_type ==PACKET_MULTICAST ) {struct in_device *in_dev =__in_dev_get_rcu (dev);
@@ -422,11 +423,11 @@ int ip_rcv(struct sk_buff *skb, struct net_device *dev, struct packet_type *pt, net =dev_net (dev); -__IP_UPD_PO_STATS (net,IPSTATS_MIB_IN , skb->len); +__IP_UPD_PO_STATS (net, dev,IPSTATS_MIB_IN , skb->len); skb =skb_share_check (skb,GFP_ATOMIC );if (!skb) { -__IP_INC_STATS (net,IPSTATS_MIB_INDISCARDS ); +__IP_INC_STATS (net, dev,IPSTATS_MIB_INDISCARDS ); goto out; }
@@ -452,7 +453,7 @@ int ip_rcv(struct sk_buff *skb, struct net_device *dev, struct packet_type *pt,BUILD_BUG_ON (IPSTATS_MIB_ECT1PKTS !=IPSTATS_MIB_NOECTPKTS +INET_ECN_ECT_1 );BUILD_BUG_ON (IPSTATS_MIB_ECT0PKTS !=IPSTATS_MIB_NOECTPKTS +INET_ECN_ECT_0 );BUILD_BUG_ON (IPSTATS_MIB_CEPKTS !=IPSTATS_MIB_NOECTPKTS +INET_ECN_CE ); -__IP_ADD_STATS (net, +__IP_ADD_STATS (net, dev,IPSTATS_MIB_NOECTPKTS + (iph->tos &INET_ECN_MASK ), max_t(unsigned short, 1, skb_shinfo(skb)->gso_segs));
@@ -466,7 +467,7 @@ int ip_rcv(struct sk_buff *skb, struct net_device *dev, struct packet_type *pt, len =ntohs (iph->tot_len);if (skb->len < len) { -__IP_INC_STATS (net,IPSTATS_MIB_INTRUNCATEDPKTS ); +__IP_INC_STATS (net, dev,IPSTATS_MIB_INTRUNCATEDPKTS ); goto drop; }else if (len < (iph->ihl*4 )) goto inhdr_error;
@@ -476,7 +477,7 @@ int ip_rcv(struct sk_buff *skb, struct net_device *dev, struct packet_type *pt,* Note this now means skb->len holds ntohs(iph->tot_len). */ if (pskb_trim_rcsum (skb, len)) { -__IP_INC_STATS (net,IPSTATS_MIB_INDISCARDS ); +__IP_INC_STATS (net, dev,IPSTATS_MIB_INDISCARDS ); goto drop; }
@@ -494,9 +495,9 @@ int ip_rcv(struct sk_buff *skb, struct net_device *dev, struct packet_type *pt, ip_rcv_finish); csum_error: -__IP_INC_STATS (net,IPSTATS_MIB_CSUMERRORS ); +__IP_INC_STATS (net, dev,IPSTATS_MIB_CSUMERRORS ); inhdr_error: -__IP_INC_STATS (net,IPSTATS_MIB_INHDRERRORS ); +__IP_INC_STATS (net, dev,IPSTATS_MIB_INHDRERRORS ); drop:kfree_skb (skb); out:
net/ipv4/ip_output.c +24 -16
@@ -191,9 +191,9 @@ static int ip_finish_output2(struct net *net, struct sock *sk, struct sk_buff *su32 nexthop;if (rt->rt_type ==RTN_MULTICAST ) { -IP_UPD_PO_STATS (net,IPSTATS_MIB_OUTMCAST , skb->len); +IP_UPD_PO_STATS (net, dev,IPSTATS_MIB_OUTMCAST , skb->len); }else if (rt->rt_type ==RTN_BROADCAST ) -IP_UPD_PO_STATS (net,IPSTATS_MIB_OUTBCAST , skb->len); +IP_UPD_PO_STATS (net, dev,IPSTATS_MIB_OUTBCAST , skb->len);/* Be paranoid, rather than too clever. */ if (unlikely (skb_headroom (skb) < hh_len && dev->header_ops)) {
@@ -339,7 +339,7 @@ int ip_mc_output(struct net *net, struct sock *sk, struct sk_buff *skb)/* * If the indicated interface is up and running, send the packet. */ -IP_UPD_PO_STATS (net,IPSTATS_MIB_OUT , skb->len); +IP_UPD_PO_STATS (net, dev,IPSTATS_MIB_OUT , skb->len); skb->dev = dev; skb->protocol =htons (ETH_P_IP );
@@ -397,7 +397,7 @@ int ip_output(struct net *net, struct sock *sk, struct sk_buff *skb) {struct net_device *dev =skb_dst (skb)->dev; -IP_UPD_PO_STATS (net,IPSTATS_MIB_OUT , skb->len); +IP_UPD_PO_STATS (net, dev,IPSTATS_MIB_OUT , skb->len); skb->dev = dev; skb->protocol =htons (ETH_P_IP );
@@ -507,7 +507,7 @@ int ip_queue_xmit(struct sock *sk, struct sk_buff *skb, struct flowi *fl) no_route:rcu_read_unlock (); -IP_INC_STATS (net,IPSTATS_MIB_OUTNOROUTES ); +IP_INC_STATS (net,NULL ,IPSTATS_MIB_OUTNOROUTES );kfree_skb (skb);return -EHOSTUNREACH ; }
@@ -548,7 +548,7 @@ static int ip_fragment(struct net *net, struct sock *sk, struct sk_buff *skb,if (unlikely (!skb->ignore_df || (IPCB (skb)->frag_max_size &&IPCB (skb)->frag_max_size > mtu))) { -IP_INC_STATS (net,IPSTATS_MIB_FRAGFAILS ); +IP_INC_STATS (net, skb->dev,IPSTATS_MIB_FRAGFAILS );icmp_send (skb,ICMP_DEST_UNREACH ,ICMP_FRAG_NEEDED ,htonl (mtu));kfree_skb (skb);
@@ -575,8 +575,11 @@ int ip_do_fragment(struct net *net, struct sock *sk, struct sk_buff *skb,int offset;__be16 not_last_frag;struct rtable *rt =skb_rtable (skb); +struct net_device *dev = rt->dst.dev;int err =0 ; +dev_hold (dev); +/* for offloaded checksums cleanup checksum before fragmentation */ if (skb->ip_summed ==CHECKSUM_PARTIAL && (err =skb_checksum_help (skb)))
@@ -675,7 +678,7 @@ int ip_do_fragment(struct net *net, struct sock *sk, struct sk_buff *skb, err =output (net, sk, skb);if (!err) -IP_INC_STATS (net,IPSTATS_MIB_FRAGCREATES ); +IP_INC_STATS (net, dev,IPSTATS_MIB_FRAGCREATES );if (err || !frag)break ;
@@ -685,7 +688,8 @@ int ip_do_fragment(struct net *net, struct sock *sk, struct sk_buff *skb, }if (err ==0 ) { -IP_INC_STATS (net,IPSTATS_MIB_FRAGOKS ); +IP_INC_STATS (net, dev,IPSTATS_MIB_FRAGOKS ); +dev_put (dev);return 0 ; }
@@ -694,7 +698,8 @@ int ip_do_fragment(struct net *net, struct sock *sk, struct sk_buff *skb,kfree_skb (frag); frag = skb; } -IP_INC_STATS (net,IPSTATS_MIB_FRAGFAILS ); +IP_INC_STATS (net, dev,IPSTATS_MIB_FRAGFAILS ); +dev_put (dev);return err; slow_path_clean:
@@ -811,15 +816,17 @@ int ip_do_fragment(struct net *net, struct sock *sk, struct sk_buff *skb,if (err) goto fail; -IP_INC_STATS (net,IPSTATS_MIB_FRAGCREATES ); +IP_INC_STATS (net, dev,IPSTATS_MIB_FRAGCREATES ); }consume_skb (skb); -IP_INC_STATS (net,IPSTATS_MIB_FRAGOKS ); +IP_INC_STATS (net, dev,IPSTATS_MIB_FRAGOKS ); +dev_put (dev);return err; fail:kfree_skb (skb); -IP_INC_STATS (net,IPSTATS_MIB_FRAGFAILS ); +IP_INC_STATS (net, dev,IPSTATS_MIB_FRAGFAILS ); +dev_put (dev);return err; }EXPORT_SYMBOL (ip_do_fragment);
@@ -1097,7 +1104,7 @@ static int __ip_append_data(struct sock *sk, err = -EFAULT ; error: cork->length -= length; -IP_INC_STATS (sock_net (sk),IPSTATS_MIB_OUTDISCARDS ); +IP_INC_STATS (sock_net (sk), rt->dst.dev,IPSTATS_MIB_OUTDISCARDS );refcount_add (wmem_alloc_delta, &sk->sk_wmem_alloc);return err; }
@@ -1305,7 +1312,7 @@ ssize_t ip_append_page(struct sock *sk, struct flowi4 *fl4, struct page *page, error: cork->length -= size; -IP_INC_STATS (sock_net (sk),IPSTATS_MIB_OUTDISCARDS ); +IP_INC_STATS (sock_net (sk), rt->dst.dev,IPSTATS_MIB_OUTDISCARDS );return err; }
@@ -1406,7 +1413,7 @@ struct sk_buff *__ip_make_skb(struct sock *sk,skb_dst_set (skb, &rt->dst);if (iph->protocol ==IPPROTO_ICMP ) -icmp_out_count (net, ((struct icmphdr *) +icmp_out_count (skb_dst (skb)->dev, ((struct icmphdr *)skb_transport_header (skb))->type);ip_cork_release (cork);
@@ -1417,13 +1424,14 @@ struct sk_buff *__ip_make_skb(struct sock *sk,int ip_send_skb (struct net *net,struct sk_buff *skb) {int err; +struct net_device *dev =skb_dst (skb)->dev; err =ip_local_out (net, skb->sk, skb);if (err) {if (err >0 ) err =net_xmit_errno (err);if (err) -IP_INC_STATS (net,IPSTATS_MIB_OUTDISCARDS ); +IP_INC_STATS (net, dev,IPSTATS_MIB_OUTDISCARDS ); }return err;
net/ipv4/ipmr.c +3 -3
@@ -1778,8 +1778,8 @@ static inline int ipmr_forward_finish(struct net *net, struct sock *sk, {struct ip_options *opt = &(IPCB (skb)->opt); -IP_INC_STATS (net,IPSTATS_MIB_OUTFORWDATAGRAMS ); -IP_ADD_STATS (net,IPSTATS_MIB_OUTOCTETS , skb->len); +IP_INC_STATS (net,skb_dst (skb)->dev,IPSTATS_MIB_OUTFORWDATAGRAMS ); +IP_ADD_STATS (net,skb_dst (skb)->dev,IPSTATS_MIB_OUTOCTETS , skb->len);if (unlikely (opt->optlen))ip_forward_options (skb);
@@ -1862,7 +1862,7 @@ static void ipmr_queue_xmit(struct net *net, struct mr_table *mrt,* allow to send ICMP, so that packets will disappear * to blackhole. */ -IP_INC_STATS (net,IPSTATS_MIB_FRAGFAILS ); +IP_INC_STATS (net, dev,IPSTATS_MIB_FRAGFAILS );ip_rt_put (rt); goto out_free; }
net/ipv4/ping.c +7 -2
@@ -712,6 +712,7 @@ static int ping_v4_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)__be32 saddr, daddr, faddr;u8 tos;int err; +struct net_device *dev;pr_debug ("ping_v4_sendmsg(sk=%p,sk->num=%u)\n" , inet, inet->inet_num);
@@ -805,7 +806,7 @@ static int ping_v4_sendmsg(struct sock *sk, struct msghdr *msg, size_t len) err =PTR_ERR (rt); rt =NULL ;if (err == -ENETUNREACH ) -IP_INC_STATS (net,IPSTATS_MIB_OUTNOROUTES ); +IP_INC_STATS (net,NULL ,IPSTATS_MIB_OUTNOROUTES ); goto out; }
@@ -841,13 +842,17 @@ static int ping_v4_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)release_sock (sk); out: + dev = rt->dst.dev; +dev_hold (dev);ip_rt_put (rt);if (free)kfree (ipc.opt);if (!err) { -icmp_out_count (sock_net (sk), user_icmph.type); +icmp_out_count (dev, user_icmph.type); +dev_put (dev);return len; } +dev_put (dev);return err; do_confirm:
net/ipv4/proc.c +126 -0
153 lines not on this page · raw message
net/ipv4/raw.c +2 -2
@@ -425,7 +425,7 @@ static int raw_send_hdrinc(struct sock *sk, struct flowi4 *fl4, skb->transport_header += iphlen;if (iph->protocol ==IPPROTO_ICMP && length >= iphlen +sizeof (struct icmphdr )) -icmp_out_count (net, ((struct icmphdr *) +icmp_out_count (rt->dst.dev, ((struct icmphdr *)skb_transport_header (skb))->type); }
@@ -442,7 +442,7 @@ static int raw_send_hdrinc(struct sock *sk, struct flowi4 *fl4, error_free:kfree_skb (skb); error: -IP_INC_STATS (net,IPSTATS_MIB_OUTDISCARDS ); +IP_INC_STATS (net, rt->dst.dev,IPSTATS_MIB_OUTDISCARDS );if (err == -ENOBUFS && !inet->recverr) err =0 ;return err;
net/ipv4/route.c +3 -3
@@ -961,11 +961,11 @@ static int ip_error(struct sk_buff *skb)if (!IN_DEV_FORWARD (in_dev)) {switch (rt->dst.error) {case EHOSTUNREACH : -__IP_INC_STATS (net,IPSTATS_MIB_INADDRERRORS ); +__IP_INC_STATS (net, rt->dst.dev,IPSTATS_MIB_INADDRERRORS );break ;case ENETUNREACH : -__IP_INC_STATS (net,IPSTATS_MIB_INNOROUTES ); +__IP_INC_STATS (net, rt->dst.dev,IPSTATS_MIB_INNOROUTES );break ; } goto out;
@@ -980,7 +980,7 @@ static int ip_error(struct sk_buff *skb)break ;case ENETUNREACH : code =ICMP_NET_UNREACH ; -__IP_INC_STATS (net,IPSTATS_MIB_INNOROUTES ); +__IP_INC_STATS (net, rt->dst.dev,IPSTATS_MIB_INNOROUTES );break ;case EACCES : code =ICMP_PKT_FILTERED ;
net/ipv4/tcp_ipv4.c +2 -2
@@ -194,7 +194,7 @@ int tcp_v4_connect(struct sock *sk, struct sockaddr *uaddr, int addr_len)if (IS_ERR (rt)) { err =PTR_ERR (rt);if (err == -ENETUNREACH ) -IP_INC_STATS (sock_net (sk),IPSTATS_MIB_OUTNOROUTES ); +IP_INC_STATS (sock_net (sk),NULL ,IPSTATS_MIB_OUTNOROUTES );return err; }
@@ -402,7 +402,7 @@ void tcp_v4_err(struct sk_buff *icmp_skb, u32 info) th->dest, iph->saddr,ntohs (th->source), inet_iif(icmp_skb), 0);if (!sk) { -__ICMP_INC_STATS (net,ICMP_MIB_INERRORS ); +__ICMP_INC_STATS (net, icmp_skb->dev,ICMP_MIB_INERRORS );return ; }if (sk->sk_state ==TCP_TIME_WAIT ) {
net/ipv4/udp.c +2 -2
@@ -609,7 +609,7 @@ void __udp4_lib_err(struct sk_buff *skb, u32 info, struct udp_table *udptable) iph->saddr, uh->source, skb->dev->ifindex,0 , udptable, NULL);if (!sk) { -__ICMP_INC_STATS (net,ICMP_MIB_INERRORS ); +__ICMP_INC_STATS (net, skb->dev,ICMP_MIB_INERRORS );return ;/* No socket for error */ }
@@ -1008,7 +1008,7 @@ int udp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len) err =PTR_ERR (rt); rt =NULL ;if (err == -ENETUNREACH ) -IP_INC_STATS (net,IPSTATS_MIB_OUTNOROUTES ); +IP_INC_STATS (net,NULL ,IPSTATS_MIB_OUTNOROUTES ); goto out; }
net/l2tp/l2tp_ip.c +2 -2
@@ -381,7 +381,7 @@ static int l2tp_ip_backlog_recv(struct sock *sk, struct sk_buff *skb)return 0 ; drop: -IP_INC_STATS (sock_net (sk),IPSTATS_MIB_INDISCARDS ); +IP_INC_STATS (sock_net (sk), skb->dev,IPSTATS_MIB_INDISCARDS );kfree_skb (skb);return 0 ; }
@@ -504,7 +504,7 @@ static int l2tp_ip_sendmsg(struct sock *sk, struct msghdr *msg, size_t len) no_route:rcu_read_unlock (); -IP_INC_STATS (sock_net (sk),IPSTATS_MIB_OUTNOROUTES ); +IP_INC_STATS (sock_net (sk),NULL ,IPSTATS_MIB_OUTNOROUTES );kfree_skb (skb); rc = -EHOSTUNREACH ; goto out;
net/l2tp/l2tp_ip6.c +1 -1
@@ -462,7 +462,7 @@ static int l2tp_ip6_backlog_recv(struct sock *sk, struct sk_buff *skb)return 0 ; drop: -IP_INC_STATS (sock_net (sk),IPSTATS_MIB_INDISCARDS ); +IP_INC_STATS (sock_net (sk), skb->dev,IPSTATS_MIB_INDISCARDS );kfree_skb (skb);return -1 ; }
net/mpls/af_mpls.c +1 -1
@@ -141,7 +141,7 @@ void mpls_stats_inc_outucastpkts(struct net_device *dev, tx_packets, tx_bytes); }else if (skb->protocol ==htons (ETH_P_IP )) { -IP_UPD_PO_STATS (dev_net (dev),IPSTATS_MIB_OUT , skb->len); +IP_UPD_PO_STATS (dev_net (dev), dev,IPSTATS_MIB_OUT , skb->len);#if IS_ENABLED (CONFIG_IPV6 ) } else if (skb->protocol == htons(ETH_P_IPV6)) {struct inet6_dev *in6dev =__in6_dev_get (dev);
net/netfilter/ipvs/ip_vs_xmit.c +1 -1
@@ -286,7 +286,7 @@ static inline bool decrement_ttl(struct netns_ipvs *ipvs, {if (ip_hdr (skb)->ttl <=1 ) {/* Tell the sender its packet died... */ -__IP_INC_STATS (net,IPSTATS_MIB_INHDRERRORS ); +__IP_INC_STATS (net,skb_dst (skb)->dev,IPSTATS_MIB_INHDRERRORS );icmp_send (skb,ICMP_TIME_EXCEEDED ,ICMP_EXC_TTL ,0 );return false; }
net/sctp/input.c +1 -1
@@ -596,7 +596,7 @@ void sctp_v4_err(struct sk_buff *skb, __u32 info) skb->network_header = saveip; skb->transport_header = savesctp;if (!sk) { -__ICMP_INC_STATS (net,ICMP_MIB_INERRORS ); +__ICMP_INC_STATS (net, skb->dev,ICMP_MIB_INERRORS );return ; }/* Warning: The sock lock is held. Remember to call
net/sctp/output.c +1 -1
@@ -600,7 +600,7 @@ int sctp_packet_transmit(struct sctp_packet *packet, gfp_t gfp)/* drop packet if no dst */ dst =dst_clone (tp->dst);if (!dst) { -IP_INC_STATS (sock_net (sk),IPSTATS_MIB_OUTNOROUTES ); +IP_INC_STATS (sock_net (sk),NULL ,IPSTATS_MIB_OUTNOROUTES );kfree_skb (head); goto out; }
Signature · 1 line
2.7.4
Quoted 5 lines · On Tue, 10 Apr 2018 22:55:35 -0400 Stephen Suryaputra <[email protected]>…
This is enhanced from the proposed patch by Igor Maravic in 2011 to support per interface IPv4 stats. The enhancement is mainly adding a kernel configuration option
CONFIG_IP_IFSTATS_TABLE.Signed-off-by Stephen Suryaputra <[email protected]>
Net-next is closed. http://vger.kernel.org/~davem/net-next.html
Also, these kind of statistics have a negative performance impact.
I read the thread and understand some of the concerns, but these are useful for network equipments. That's why in this patch, I made it as configuration option.
If you have feedbacks, I'll appreciate them.
I can resend when net-next is opened again.
Thanks.
Quoted 13 lines · Stephen Hemminger
Quoted 5 lines · On Tue, 10 Apr 2018 22:55:35 -0400 Stephen Suryaputra <[email protected]>…
This is enhanced from the proposed patch by Igor Maravic in 2011 to support per interface IPv4 stats. The enhancement is mainly adding a kernel configuration option
CONFIG_IP_IFSTATS_TABLE.Signed-off-by Stephen Suryaputra <[email protected]>Net-next is closed. http://vger.kernel.org/~davem/net-next.html
Also, these kind of statistics have a negative performance impact.
Julian Anastasov
maintainerHello,
Quoted 6 lines · Stephen Suryaputra
This is enhanced from the proposed patch by Igor Maravic in 2011 to support per interface IPv4 stats. The enhancement is mainly adding a kernel configuration option
CONFIG_IP_IFSTATS_TABLE.Signed-off-by Stephen Suryaputra <[email protected]>---
...
Quoted 25 lines
net/ipv4/ip_forward.c +3
-3@@ -66,8 +66,8 @@ static int ip_forward_finish(struct net *net, struct sock *sk, struct sk_buff *s {struct ip_options *opt = &(IPCB (skb)->opt); -__IP_INC_STATS (net,IPSTATS_MIB_OUTFORWDATAGRAMS ); -__IP_ADD_STATS (net,IPSTATS_MIB_OUTOCTETS , skb->len); +__IP_INC_STATS (net,skb_dst (skb)->dev,IPSTATS_MIB_OUTFORWDATAGRAMS ); +__IP_ADD_STATS (net,skb_dst (skb)->dev,IPSTATS_MIB_OUTOCTETS , skb->len);if (unlikely (opt->optlen))ip_forward_options (skb);@@ -121,7 +121,7 @@ int ip_forward(struct sk_buff *skb)IPCB (skb)->flags |=IPSKB_FORWARDED ; mtu =ip_dst_mtu_maybe_forward (&rt->dst, true);if (ip_exceeds_mtu (skb, mtu)) { -IP_INC_STATS (net,IPSTATS_MIB_FRAGFAILS ); +IP_INC_STATS (net, rt->dst.dev,IPSTATS_MIB_FRAGFAILS );icmp_send (skb,ICMP_DEST_UNREACH ,ICMP_FRAG_NEEDED ,htonl (mtu)); goto drop;
net/ipv4/ip_forward.c int ip_forward(struct sk_buff *skb) · line 161
Quoted 5 lines
net/ipv4/ip_forward.c +1
-1@@ -158,7 +158,7 @@ int ip_forward(struct sk_buff *skb) too_many_hops:/* Tell the sender its packet died... */ -__IP_INC_STATS (net,IPSTATS_MIB_INHDRERRORS ); +__IP_INC_STATS (net,skb_dst (skb)->dev,IPSTATS_MIB_INHDRERRORS );
May be skb->dev if we want to account it to the
input device.
Quoted 3 lines
net/ipv4/ip_forward.c +0
-0icmp_send (skb,ICMP_TIME_EXCEEDED ,ICMP_EXC_TTL ,0 ); drop:kfree_skb (skb);
...
net/netfilter/ipvs/ip_vs_xmit.c static inline bool decrement_ttl(struct netns_ipvs *ipvs, · line 289
Quoted 10 lines
net/netfilter/ipvs/ip_vs_xmit.c +1
-1@@ -286,7 +286,7 @@ static inline bool decrement_ttl(struct netns_ipvs *ipvs, {if (ip_hdr (skb)->ttl <=1 ) {/* Tell the sender its packet died... */ -__IP_INC_STATS (net,IPSTATS_MIB_INHDRERRORS ); +__IP_INC_STATS (net,skb_dst (skb)->dev,IPSTATS_MIB_INHDRERRORS );
At this point, skb_dst(skb) can be:
- input route at LOCAL_IN => dst->dev is "lo", skb->dev = input_device
- output route at LOCAL_OUT => dst->dev is output_device, skb->dev = NULL
We should see this error on LOCAL_IN but better to be
safe: use 'skb->dev ? : skb_dst(skb)->dev' instead of just 'skb_dst(skb)->dev'.
net/netfilter/ipvs/ip_vs_xmit.c static inline bool decrement_ttl(struct netns_ipvs *ipvs, · line 292
Quoted 3 lines
net/netfilter/ipvs/ip_vs_xmit.c +0
-0icmp_send (skb,ICMP_TIME_EXCEEDED ,ICMP_EXC_TTL ,0 );return false; }
The patch probably has other errors, for example,
using rt->dst.dev (lo) when rt->dst.error != 0 in ip_error, may be 'dev' should be used instead...
Regards
Thanks for the feedbacks. Please see the detail below:
On Wed, Apr 11, 2018 at 3:37 PM, Julian Anastasov <[email protected]> wrote:
[snip]
Quoted 6 lines
Review
Quoted 2 lines
(quoted diff) +1
-1- __IP_INC_STATS(net, IPSTATS_MIB_INHDRERRORS); + __IP_INC_STATS(net, skb_dst(skb)->dev, IPSTATS_MIB_INHDRERRORS);May be skb->dev if we want to account it to theinput device.
Yes. I'm about to make change it but see the next one.
[snip]
Quoted 13 lines
net/netfilter/ipvs/ip_vs_xmit.c static inline bool decrement_ttl(struct netns_ipvs *ipvs, · line 289
Quoted 10 lines
net/netfilter/ipvs/ip_vs_xmit.c +1
-1@@ -286,7 +286,7 @@ static inline bool decrement_ttl(struct netns_ipvs *ipvs, {if (ip_hdr (skb)->ttl <=1 ) {/* Tell the sender its packet died... */ -__IP_INC_STATS (net,IPSTATS_MIB_INHDRERRORS ); +__IP_INC_STATS (net,skb_dst (skb)->dev,IPSTATS_MIB_INHDRERRORS );At this point,
skb_dst(skb)can be:
Quoted 7 lines
- input route at
LOCAL_IN=>dst->devis "lo",skb->dev=input_device
- output route atLOCAL_OUT=>dst->devisoutput_device,skb->dev= NULLWe should see this error on
LOCAL_INbut better to be
safe: use 'skb->dev? : skb_dst(skb)->dev' instead of just 'skb_dst(skb)->dev'.
This follows v6 implementation in the same function:
#ifdef CONFIG_IP_VS_IPV6
if (skb_af == AF_INET6) {
struct dst_entry *dst = skb_dst(skb);
/* check and decrement ttl */
if (ipv6_hdr(skb)->hop_limit <= 1) {
/* Force OUTPUT device used as source address */
skb->dev = dst->dev;
icmpv6_send(skb, ICMPV6_TIME_EXCEED,
ICMPV6_EXC_HOPLIMIT, 0);
__IP6_INC_STATS(net, ip6_dst_idev(dst),
IPSTATS_MIB_INHDRERRORS);
return false;
}
/* don't propagate ttl change to cloned packets */
if (!skb_make_writable(skb, sizeof(struct ipv6hdr)))
return false;
ipv6_hdr(skb)->hop_limit--;
} else#endif
[snip]
Quoted 4 lines
The patch probably has other errors, for example,
usingrt->dst.dev(lo) whenrt->dst.error!= 0 inip_error, may be 'dev' should be used instead...
Same also here. Examples are ip6_forward and ip6_pkt_drop.
I think it's better be counted in the input device for them also. Thoughts?
Regards,
Stephen.
Julian Anastasov
maintainerHello,
Quoted 35 lines · Stephen Suryaputra
Thanks for the feedbacks. Please see the detail below:
On Wed, Apr 11, 2018 at 3:37 PM, Julian Anastasov <[email protected]> wrote:
[snip]Quoted 6 lines
Review
Quoted 2 lines
(quoted diff) +1
-1- __IP_INC_STATS(net, IPSTATS_MIB_INHDRERRORS); + __IP_INC_STATS(net, skb_dst(skb)->dev, IPSTATS_MIB_INHDRERRORS);May be skb->dev if we want to account it to theinput device.
Yes. I'm about to make change it but see the next one.
[snip]
Quoted 13 lines
net/netfilter/ipvs/ip_vs_xmit.c static inline bool decrement_ttl(struct netns_ipvs *ipvs, · line 289
Quoted 10 lines
net/netfilter/ipvs/ip_vs_xmit.c +1
-1@@ -286,7 +286,7 @@ static inline bool decrement_ttl(struct netns_ipvs *ipvs, {if (ip_hdr (skb)->ttl <=1 ) {/* Tell the sender its packet died... */ -__IP_INC_STATS (net,IPSTATS_MIB_INHDRERRORS ); +__IP_INC_STATS (net,skb_dst (skb)->dev,IPSTATS_MIB_INHDRERRORS );At this point,
skb_dst(skb)can be:Quoted 7 lines
- input route at
LOCAL_IN=>dst->devis "lo",skb->dev=input_device
- output route atLOCAL_OUT=>dst->devisoutput_device,skb->dev= NULLWe should see this error on
LOCAL_INbut better to be
safe: use 'skb->dev? : skb_dst(skb)->dev' instead of just 'skb_dst(skb)->dev'.This follows v6 implementation in the same function:
Quoted 7 lines
#ifdef CONFIG_IP_VS_IPV6
if (skb_af == AF_INET6) {
struct dst_entry *dst = skb_dst(skb);
/* check and decrement ttl */
if (ipv6_hdr(skb)->hop_limit <= 1) {
/* Force OUTPUT device used as source address */ It looks like IPVS copied it from ip6_forward() but in
IPVS context it has its reason: we want ICMP to exit with saddr=Virtual_IP. And we are at LOCAL_IN where there is no output device like in ip6_forward(FORWARD) to use its source address.
So, IPVS is special (both input and output path) and needs:
IPv4: skb->dev ? : skb_dst(skb)->dev
IPv6 needs fix for IPVS stats in decrement_ttl:
idev = skb->dev ? __in6_dev_get(skb->dev) : ip6_dst_idev(dst); ... __IP6_INC_STATS(net, idev, IPSTATS_MIB_INHDRERRORS); Otherwise, stats will go to "lo" if ip6_dst_idev
is used for local input route.
So, for accounting on input IPv4 path skb->dev should be
used, while for IPv6 some sites may prefer to feed icmpv6_send() with output dst->dev as device containing the source address (skb->dev). But this is unrelated to the stats.
Quoted 19 lines
skb->dev = dst->dev; icmpv6_send(skb, ICMPV6_TIME_EXCEED, ICMPV6_EXC_HOPLIMIT, 0); __IP6_INC_STATS(net, ip6_dst_idev(dst), IPSTATS_MIB_INHDRERRORS); return false; } /* don't propagate ttl change to cloned packets */ if (!skb_make_writable(skb, sizeof(struct ipv6hdr))) return false; ipv6_hdr(skb)->hop_limit--; } else#endif
[snip]
Quoted 1 line
Quoted 7 lines
Quoted 3 lines
The patch probably has other errors, for example,
usingrt->dst.dev(lo) whenrt->dst.error!= 0 inip_error, may be 'dev' should be used instead...Same also here. Examples are
ip6_forwardandip6_pkt_drop.I think it's better be counted in the input device for them also. Thoughts?
I think so. ipv6_rcv() works with idev = __in6_dev_get(skb->dev)
but I don't know IPv6 well and whether ip6_dst_idev(skb_dst(skb)) is correct usage for input path. It should be correct for output path, though.
Regards
kbuild test robot
build botThank you for the patch! Perhaps something to improve:
Hi Stephen,
Thank you for the patch! Perhaps something to improve:
[auto build test WARNING on net-next/master]
url: https://github.com/0day-ci/linux/commits/Stephen-Suryaputra/Per-interface-IPv4-stats-CONFIG_IP_IFSTATS_TABLE/20180412-181719
reproduce:
# apt-get install sparse
make ARCH=x86_64 allmodconfig
make C=1 CF=-D__CHECK_ENDIAN__sparse warnings: (new ones prefixed by >>)
net/ipv4/proc.c:414:28: sparse: Variable length array is used.
>> net/ipv4/proc.c:499:43: sparse: incorrect type in argument 1 (different address spaces) @@ expected void [noderef] <asn:3>*mib @@ got vvoid [noderef] <asn:3>*mib @@ net/ipv4/proc.c:499:43: expected void [noderef] <asn:3>*mib net/ipv4/proc.c:499:43: got void [noderef] <asn:3>**pcpumib >> net/ipv4/proc.c:532:34: sparse: cast removes address space of expression
net/ipv4/proc.c:534:34: sparse: cast removes address space of expression
vim +499 net/ipv4/proc.c
411
412 static int snmp_seq_show_tcp_udp(struct seq_file *seq, void *v)
413 {
> 414 unsigned long buff[TCPUDP_MIB_MAX];
415 struct net *net = seq->private;
416 int i;
417
418 memset(buff, 0, TCPUDP_MIB_MAX * sizeof(unsigned long));
419
420 seq_puts(seq, "\nTcp:");
421 for (i = 0; snmp4_tcp_list[i].name; i++)
422 seq_printf(seq, " %s", snmp4_tcp_list[i].name);
423
424 seq_puts(seq, "\nTcp:");
425 snmp_get_cpu_field_batch(buff, snmp4_tcp_list,
426 net->mib.tcp_statistics);
427 for (i = 0; snmp4_tcp_list[i].name; i++) {
428 /* MaxConn field is signed, RFC 2012 */
429 if (snmp4_tcp_list[i].entry == TCP_MIB_MAXCONN)
430 seq_printf(seq, " %ld", buff[i]);
431 else
432 seq_printf(seq, " %lu", buff[i]);
433 }
434
435 memset(buff, 0, TCPUDP_MIB_MAX * sizeof(unsigned long));
436
437 snmp_get_cpu_field_batch(buff, snmp4_udp_list,
438 net->mib.udp_statistics);
439 seq_puts(seq, "\nUdp:");
440 for (i = 0; snmp4_udp_list[i].name; i++)
441 seq_printf(seq, " %s", snmp4_udp_list[i].name);
442 seq_puts(seq, "\nUdp:");
443 for (i = 0; snmp4_udp_list[i].name; i++)
444 seq_printf(seq, " %lu", buff[i]);
445
446 memset(buff, 0, TCPUDP_MIB_MAX * sizeof(unsigned long));
447
448 /* the UDP and UDP-Lite MIBs are the same */
449 seq_puts(seq, "\nUdpLite:");
450 snmp_get_cpu_field_batch(buff, snmp4_udp_list,
451 net->mib.udplite_statistics);
452 for (i = 0; snmp4_udp_list[i].name; i++)
453 seq_printf(seq, " %s", snmp4_udp_list[i].name);
454 seq_puts(seq, "\nUdpLite:");
455 for (i = 0; snmp4_udp_list[i].name; i++)
456 seq_printf(seq, " %lu", buff[i]);
457
458 seq_putc(seq, '\n');
459 return 0;
460 }
461
462 static int snmp_seq_show(struct seq_file *seq, void *v)
463 {
464 snmp_seq_show_ipstats(seq, v);
465
466 icmp_put(seq); /* RFC 2011 compatibility */
467 icmpmsg_put(seq);
468
469 snmp_seq_show_tcp_udp(seq, v);
470
471 return 0;
472 }
473
474 static int snmp_seq_open(struct inode *inode, struct file *file)
475 {
476 return single_open_net(inode, file, snmp_seq_show);
477 }
478
479 static const struct file_operations snmp_seq_fops = {
480 .open = snmp_seq_open,
481 .read = seq_read,
482 .llseek = seq_lseek,
483 .release = single_release_net,
484 };
485
486
487 #ifdef CONFIG_IP_IFSTATS_TABLE
488 static void snmp_seq_show_item(struct seq_file *seq, void __percpu **pcpumib,
489 atomic_long_t *smib,
490 const struct snmp_mib *itemlist,
491 char *prefix)
492 {
493 char name[32];
494 int i;
495 unsigned long val;
496
497 for (i = 0; itemlist[i].name; i++) {
498 val = pcpumib ?
> 499 snmp_fold_field64(pcpumib, itemlist[i].entry,
500 offsetof(struct ipstats_mib, syncp)) :
501 atomic_long_read(smib + itemlist[i].entry);
502 snprintf(name, sizeof(name), "%s%s",
503 prefix, itemlist[i].name);
504 seq_printf(seq, "%-32s\t%lu\n", name, val);
505 }
506 }
507
508 static void snmp_seq_show_icmpmsg(struct seq_file *seq, atomic_long_t *smib)
509 {
510 char name[32];
511 int i;
512 unsigned long val;
513
514 for (i = 0; i < ICMPMSG_MIB_MAX; i++) {
515 val = atomic_long_read(smib + i);
516 if (val) {
517 snprintf(name, sizeof(name), "Icmp%sType%u",
518 i & 0x100 ? "Out" : "In", i & 0xff);
519 seq_printf(seq, "%-32s\t%lu\n", name, val);
520 }
521 }
522 }
523
524 static int snmp_dev_seq_show(struct seq_file *seq, void *v)
525 {
526 struct in_device *idev = (struct in_device *)seq->private;
527
528 seq_printf(seq, "%-32s\t%u\n", "ifIndex", idev->dev->ifindex);
529
530 BUILD_BUG_ON(offsetof(struct ipstats_mib, mibs) != 0);
531
> 532 snmp_seq_show_item(seq, (void __percpu **)idev->stats.ip, NULL, 533 snmp4_ipstats_list, "Ip");
534 snmp_seq_show_item(seq, (void __percpu **)idev->stats.ip, NULL,
535 snmp4_ipextstats_list, "Ip");
536 snmp_seq_show_item(seq, NULL, idev->stats.icmpdev->mibs,
537 snmp4_icmp_list, "Icmp");
538 snmp_seq_show_icmpmsg(seq, idev->stats.icmpmsgdev->mibs);
539 return 0;
540 }
541
---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation