Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 #ifndef _NET_DST_OPS_H
0003 #define _NET_DST_OPS_H
0004 #include <linux/types.h>
0005 #include <linux/percpu_counter.h>
0006 #include <linux/cache.h>
0007 
0008 struct dst_entry;
0009 struct kmem_cachep;
0010 struct net_device;
0011 struct sk_buff;
0012 struct sock;
0013 struct net;
0014 
0015 struct dst_ops {
0016     unsigned short      family;
0017     unsigned int        gc_thresh;
0018 
0019     int         (*gc)(struct dst_ops *ops);
0020     struct dst_entry *  (*check)(struct dst_entry *, __u32 cookie);
0021     unsigned int        (*default_advmss)(const struct dst_entry *);
0022     unsigned int        (*mtu)(const struct dst_entry *);
0023     u32 *           (*cow_metrics)(struct dst_entry *, unsigned long);
0024     void            (*destroy)(struct dst_entry *);
0025     void            (*ifdown)(struct dst_entry *,
0026                       struct net_device *dev, int how);
0027     struct dst_entry *  (*negative_advice)(struct dst_entry *);
0028     void            (*link_failure)(struct sk_buff *);
0029     void            (*update_pmtu)(struct dst_entry *dst, struct sock *sk,
0030                            struct sk_buff *skb, u32 mtu,
0031                            bool confirm_neigh);
0032     void            (*redirect)(struct dst_entry *dst, struct sock *sk,
0033                         struct sk_buff *skb);
0034     int         (*local_out)(struct net *net, struct sock *sk, struct sk_buff *skb);
0035     struct neighbour *  (*neigh_lookup)(const struct dst_entry *dst,
0036                         struct sk_buff *skb,
0037                         const void *daddr);
0038     void            (*confirm_neigh)(const struct dst_entry *dst,
0039                          const void *daddr);
0040 
0041     struct kmem_cache   *kmem_cachep;
0042 
0043     struct percpu_counter   pcpuc_entries ____cacheline_aligned_in_smp;
0044 };
0045 
0046 static inline int dst_entries_get_fast(struct dst_ops *dst)
0047 {
0048     return percpu_counter_read_positive(&dst->pcpuc_entries);
0049 }
0050 
0051 static inline int dst_entries_get_slow(struct dst_ops *dst)
0052 {
0053     return percpu_counter_sum_positive(&dst->pcpuc_entries);
0054 }
0055 
0056 #define DST_PERCPU_COUNTER_BATCH 32
0057 static inline void dst_entries_add(struct dst_ops *dst, int val)
0058 {
0059     percpu_counter_add_batch(&dst->pcpuc_entries, val,
0060                  DST_PERCPU_COUNTER_BATCH);
0061 }
0062 
0063 static inline int dst_entries_init(struct dst_ops *dst)
0064 {
0065     return percpu_counter_init(&dst->pcpuc_entries, 0, GFP_KERNEL);
0066 }
0067 
0068 static inline void dst_entries_destroy(struct dst_ops *dst)
0069 {
0070     percpu_counter_destroy(&dst->pcpuc_entries);
0071 }
0072 
0073 #endif