Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * net/dst.h Protocol independent destination cache definitions. |
| 3 | * |
| 4 | * Authors: Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru> |
| 5 | * |
| 6 | */ |
| 7 | |
| 8 | #ifndef _NET_DST_H |
| 9 | #define _NET_DST_H |
| 10 | |
Alexey Dobriyan | 86393e5 | 2009-08-29 01:34:49 +0000 | [diff] [blame] | 11 | #include <net/dst_ops.h> |
Arnaldo Carvalho de Melo | 14c8502 | 2005-12-27 02:43:12 -0200 | [diff] [blame] | 12 | #include <linux/netdevice.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | #include <linux/rtnetlink.h> |
| 14 | #include <linux/rcupdate.h> |
Paul Gortmaker | 187f188 | 2011-11-23 20:12:59 -0500 | [diff] [blame] | 15 | #include <linux/bug.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | #include <linux/jiffies.h> |
| 17 | #include <net/neighbour.h> |
| 18 | #include <asm/processor.h> |
| 19 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | #define DST_GC_MIN (HZ/10) |
| 21 | #define DST_GC_INC (HZ/2) |
| 22 | #define DST_GC_MAX (120*HZ) |
| 23 | |
| 24 | /* Each dst_entry has reference count and sits in some parent list(s). |
| 25 | * When it is removed from parent list, it is "freed" (dst_free). |
| 26 | * After this it enters dead state (dst->obsolete > 0) and if its refcnt |
| 27 | * is zero, it can be destroyed immediately, otherwise it is added |
| 28 | * to gc list and garbage collector periodically checks the refcnt. |
| 29 | */ |
| 30 | |
| 31 | struct sk_buff; |
| 32 | |
Eric Dumazet | fd2c3ef | 2009-11-03 03:26:03 +0000 | [diff] [blame] | 33 | struct dst_entry { |
Eric Dumazet | 1e19e02 | 2007-02-09 16:26:55 -0800 | [diff] [blame] | 34 | struct rcu_head rcu_head; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | struct dst_entry *child; |
| 36 | struct net_device *dev; |
David S. Miller | 62fa8a8 | 2011-01-26 20:51:05 -0800 | [diff] [blame] | 37 | struct dst_ops *ops; |
| 38 | unsigned long _metrics; |
YOSHIFUJI Hideaki / 吉藤英明 | ecd9883 | 2013-02-20 00:29:08 +0000 | [diff] [blame] | 39 | unsigned long expires; |
Zhang Yanmin | f1dd9c3 | 2008-03-12 22:52:37 -0700 | [diff] [blame] | 40 | struct dst_entry *path; |
YOSHIFUJI Hideaki / 吉藤英明 | ecd9883 | 2013-02-20 00:29:08 +0000 | [diff] [blame] | 41 | struct dst_entry *from; |
Alexey Dobriyan | def8b4f | 2008-10-28 13:24:06 -0700 | [diff] [blame] | 42 | #ifdef CONFIG_XFRM |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | struct xfrm_state *xfrm; |
Eric Dumazet | 5635c10 | 2008-11-16 19:46:36 -0800 | [diff] [blame] | 44 | #else |
| 45 | void *__pad1; |
Alexey Dobriyan | def8b4f | 2008-10-28 13:24:06 -0700 | [diff] [blame] | 46 | #endif |
Eldad Zack | 7f95e18 | 2012-06-16 15:14:49 +0200 | [diff] [blame] | 47 | int (*input)(struct sk_buff *); |
| 48 | int (*output)(struct sk_buff *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | |
David S. Miller | 5110effe | 2012-07-02 02:21:03 -0700 | [diff] [blame] | 50 | unsigned short flags; |
David S. Miller | f6b72b6 | 2011-07-14 07:53:20 -0700 | [diff] [blame] | 51 | #define DST_HOST 0x0001 |
| 52 | #define DST_NOXFRM 0x0002 |
| 53 | #define DST_NOPOLICY 0x0004 |
| 54 | #define DST_NOHASH 0x0008 |
| 55 | #define DST_NOCACHE 0x0010 |
| 56 | #define DST_NOCOUNT 0x0020 |
Hannes Frederic Sowa | e90c148 | 2014-03-06 09:11:07 +0100 | [diff] [blame^] | 57 | #define DST_FAKE_RTABLE 0x0040 |
| 58 | #define DST_XFRM_TUNNEL 0x0080 |
| 59 | #define DST_XFRM_QUEUE 0x0100 |
David S. Miller | f6b72b6 | 2011-07-14 07:53:20 -0700 | [diff] [blame] | 60 | |
David S. Miller | 5110effe | 2012-07-02 02:21:03 -0700 | [diff] [blame] | 61 | unsigned short pending_confirm; |
| 62 | |
David S. Miller | 62fa8a8 | 2011-01-26 20:51:05 -0800 | [diff] [blame] | 63 | short error; |
David S. Miller | f5b0a87 | 2012-07-19 12:31:33 -0700 | [diff] [blame] | 64 | |
| 65 | /* A non-zero value of dst->obsolete forces by-hand validation |
| 66 | * of the route entry. Positive values are set by the generic |
| 67 | * dst layer to indicate that the entry has been forcefully |
| 68 | * destroyed. |
| 69 | * |
| 70 | * Negative values are used by the implementation layer code to |
| 71 | * force invocation of the dst_ops->check() method. |
| 72 | */ |
David S. Miller | 62fa8a8 | 2011-01-26 20:51:05 -0800 | [diff] [blame] | 73 | short obsolete; |
David S. Miller | f5b0a87 | 2012-07-19 12:31:33 -0700 | [diff] [blame] | 74 | #define DST_OBSOLETE_NONE 0 |
| 75 | #define DST_OBSOLETE_DEAD 2 |
| 76 | #define DST_OBSOLETE_FORCE_CHK -1 |
David S. Miller | ceb3320 | 2012-07-17 11:31:28 -0700 | [diff] [blame] | 77 | #define DST_OBSOLETE_KILL -2 |
David S. Miller | 62fa8a8 | 2011-01-26 20:51:05 -0800 | [diff] [blame] | 78 | unsigned short header_len; /* more space at head required */ |
| 79 | unsigned short trailer_len; /* space to reserve at tail */ |
Patrick McHardy | c7066f7 | 2011-01-14 13:36:42 +0100 | [diff] [blame] | 80 | #ifdef CONFIG_IP_ROUTE_CLASSID |
Zhang Yanmin | f1dd9c3 | 2008-03-12 22:52:37 -0700 | [diff] [blame] | 81 | __u32 tclassid; |
Eric Dumazet | 5635c10 | 2008-11-16 19:46:36 -0800 | [diff] [blame] | 82 | #else |
| 83 | __u32 __pad2; |
Zhang Yanmin | f1dd9c3 | 2008-03-12 22:52:37 -0700 | [diff] [blame] | 84 | #endif |
| 85 | |
Eric Dumazet | 5635c10 | 2008-11-16 19:46:36 -0800 | [diff] [blame] | 86 | /* |
| 87 | * Align __refcnt to a 64 bytes alignment |
| 88 | * (L1_CACHE_SIZE would be too much) |
| 89 | */ |
| 90 | #ifdef CONFIG_64BIT |
David S. Miller | f6b72b6 | 2011-07-14 07:53:20 -0700 | [diff] [blame] | 91 | long __pad_to_align_refcnt[2]; |
Eric Dumazet | 5635c10 | 2008-11-16 19:46:36 -0800 | [diff] [blame] | 92 | #endif |
Zhang Yanmin | f1dd9c3 | 2008-03-12 22:52:37 -0700 | [diff] [blame] | 93 | /* |
| 94 | * __refcnt wants to be on a different cache line from |
| 95 | * input/output/ops or performance tanks badly |
| 96 | */ |
Eric Dumazet | 1e19e02 | 2007-02-09 16:26:55 -0800 | [diff] [blame] | 97 | atomic_t __refcnt; /* client references */ |
| 98 | int __use; |
Zhang Yanmin | f1dd9c3 | 2008-03-12 22:52:37 -0700 | [diff] [blame] | 99 | unsigned long lastuse; |
Eric Dumazet | 1e19e02 | 2007-02-09 16:26:55 -0800 | [diff] [blame] | 100 | union { |
Eric Dumazet | fc766e4c | 2010-10-29 03:09:24 +0000 | [diff] [blame] | 101 | struct dst_entry *next; |
| 102 | struct rtable __rcu *rt_next; |
| 103 | struct rt6_info *rt6_next; |
| 104 | struct dn_route __rcu *dn_next; |
Eric Dumazet | 1e19e02 | 2007-02-09 16:26:55 -0800 | [diff] [blame] | 105 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | }; |
| 107 | |
Joe Perches | a4023dd | 2013-09-20 11:23:21 -0700 | [diff] [blame] | 108 | u32 *dst_cow_metrics_generic(struct dst_entry *dst, unsigned long old); |
Eric Dumazet | a37e6e3 | 2012-08-07 10:55:45 +0000 | [diff] [blame] | 109 | extern const u32 dst_default_metrics[]; |
David S. Miller | 62fa8a8 | 2011-01-26 20:51:05 -0800 | [diff] [blame] | 110 | |
| 111 | #define DST_METRICS_READ_ONLY 0x1UL |
| 112 | #define __DST_METRICS_PTR(Y) \ |
| 113 | ((u32 *)((Y) & ~DST_METRICS_READ_ONLY)) |
| 114 | #define DST_METRICS_PTR(X) __DST_METRICS_PTR((X)->_metrics) |
| 115 | |
| 116 | static inline bool dst_metrics_read_only(const struct dst_entry *dst) |
| 117 | { |
| 118 | return dst->_metrics & DST_METRICS_READ_ONLY; |
| 119 | } |
| 120 | |
Joe Perches | a4023dd | 2013-09-20 11:23:21 -0700 | [diff] [blame] | 121 | void __dst_destroy_metrics_generic(struct dst_entry *dst, unsigned long old); |
David S. Miller | 62fa8a8 | 2011-01-26 20:51:05 -0800 | [diff] [blame] | 122 | |
| 123 | static inline void dst_destroy_metrics_generic(struct dst_entry *dst) |
| 124 | { |
| 125 | unsigned long val = dst->_metrics; |
| 126 | if (!(val & DST_METRICS_READ_ONLY)) |
| 127 | __dst_destroy_metrics_generic(dst, val); |
| 128 | } |
| 129 | |
| 130 | static inline u32 *dst_metrics_write_ptr(struct dst_entry *dst) |
| 131 | { |
| 132 | unsigned long p = dst->_metrics; |
| 133 | |
Stephen Hemminger | 1f37070 | 2011-05-24 13:50:52 -0400 | [diff] [blame] | 134 | BUG_ON(!p); |
| 135 | |
David S. Miller | 62fa8a8 | 2011-01-26 20:51:05 -0800 | [diff] [blame] | 136 | if (p & DST_METRICS_READ_ONLY) |
| 137 | return dst->ops->cow_metrics(dst, p); |
| 138 | return __DST_METRICS_PTR(p); |
| 139 | } |
| 140 | |
| 141 | /* This may only be invoked before the entry has reached global |
| 142 | * visibility. |
| 143 | */ |
| 144 | static inline void dst_init_metrics(struct dst_entry *dst, |
| 145 | const u32 *src_metrics, |
| 146 | bool read_only) |
| 147 | { |
| 148 | dst->_metrics = ((unsigned long) src_metrics) | |
| 149 | (read_only ? DST_METRICS_READ_ONLY : 0); |
| 150 | } |
| 151 | |
| 152 | static inline void dst_copy_metrics(struct dst_entry *dest, const struct dst_entry *src) |
| 153 | { |
| 154 | u32 *dst_metrics = dst_metrics_write_ptr(dest); |
| 155 | |
| 156 | if (dst_metrics) { |
| 157 | u32 *src_metrics = DST_METRICS_PTR(src); |
| 158 | |
| 159 | memcpy(dst_metrics, src_metrics, RTAX_MAX * sizeof(u32)); |
| 160 | } |
| 161 | } |
| 162 | |
| 163 | static inline u32 *dst_metrics_ptr(struct dst_entry *dst) |
| 164 | { |
| 165 | return DST_METRICS_PTR(dst); |
| 166 | } |
| 167 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 168 | static inline u32 |
David S. Miller | 5170ae8 | 2010-12-12 21:35:57 -0800 | [diff] [blame] | 169 | dst_metric_raw(const struct dst_entry *dst, const int metric) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | { |
David S. Miller | 62fa8a8 | 2011-01-26 20:51:05 -0800 | [diff] [blame] | 171 | u32 *p = DST_METRICS_PTR(dst); |
| 172 | |
| 173 | return p[metric-1]; |
David S. Miller | defb351 | 2010-12-08 21:16:57 -0800 | [diff] [blame] | 174 | } |
| 175 | |
David S. Miller | 5170ae8 | 2010-12-12 21:35:57 -0800 | [diff] [blame] | 176 | static inline u32 |
| 177 | dst_metric(const struct dst_entry *dst, const int metric) |
| 178 | { |
David S. Miller | 0dbaee3 | 2010-12-13 12:52:14 -0800 | [diff] [blame] | 179 | WARN_ON_ONCE(metric == RTAX_HOPLIMIT || |
David S. Miller | d33e455 | 2010-12-14 13:01:14 -0800 | [diff] [blame] | 180 | metric == RTAX_ADVMSS || |
| 181 | metric == RTAX_MTU); |
David S. Miller | 5170ae8 | 2010-12-12 21:35:57 -0800 | [diff] [blame] | 182 | return dst_metric_raw(dst, metric); |
| 183 | } |
| 184 | |
David S. Miller | 0dbaee3 | 2010-12-13 12:52:14 -0800 | [diff] [blame] | 185 | static inline u32 |
| 186 | dst_metric_advmss(const struct dst_entry *dst) |
| 187 | { |
| 188 | u32 advmss = dst_metric_raw(dst, RTAX_ADVMSS); |
| 189 | |
| 190 | if (!advmss) |
| 191 | advmss = dst->ops->default_advmss(dst); |
| 192 | |
| 193 | return advmss; |
| 194 | } |
| 195 | |
David S. Miller | defb351 | 2010-12-08 21:16:57 -0800 | [diff] [blame] | 196 | static inline void dst_metric_set(struct dst_entry *dst, int metric, u32 val) |
| 197 | { |
David S. Miller | 62fa8a8 | 2011-01-26 20:51:05 -0800 | [diff] [blame] | 198 | u32 *p = dst_metrics_write_ptr(dst); |
David S. Miller | defb351 | 2010-12-08 21:16:57 -0800 | [diff] [blame] | 199 | |
David S. Miller | 62fa8a8 | 2011-01-26 20:51:05 -0800 | [diff] [blame] | 200 | if (p) |
| 201 | p[metric-1] = val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 202 | } |
| 203 | |
Gilad Ben-Yossef | 0c3adfb | 2009-10-28 04:15:23 +0000 | [diff] [blame] | 204 | static inline u32 |
| 205 | dst_feature(const struct dst_entry *dst, u32 feature) |
| 206 | { |
David S. Miller | bb5b7c1 | 2009-12-15 20:56:42 -0800 | [diff] [blame] | 207 | return dst_metric(dst, RTAX_FEATURES) & feature; |
Gilad Ben-Yossef | 0c3adfb | 2009-10-28 04:15:23 +0000 | [diff] [blame] | 208 | } |
| 209 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 210 | static inline u32 dst_mtu(const struct dst_entry *dst) |
| 211 | { |
Steffen Klassert | 618f9bc | 2011-11-23 02:13:31 +0000 | [diff] [blame] | 212 | return dst->ops->mtu(dst); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 213 | } |
| 214 | |
Stephen Hemminger | c1e20f7 | 2008-07-18 23:02:15 -0700 | [diff] [blame] | 215 | /* RTT metrics are stored in milliseconds for user ABI, but used as jiffies */ |
| 216 | static inline unsigned long dst_metric_rtt(const struct dst_entry *dst, int metric) |
| 217 | { |
| 218 | return msecs_to_jiffies(dst_metric(dst, metric)); |
| 219 | } |
| 220 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 221 | static inline u32 |
| 222 | dst_allfrag(const struct dst_entry *dst) |
| 223 | { |
Gilad Ben-Yossef | 0c3adfb | 2009-10-28 04:15:23 +0000 | [diff] [blame] | 224 | int ret = dst_feature(dst, RTAX_FEATURE_ALLFRAG); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 225 | return ret; |
| 226 | } |
| 227 | |
| 228 | static inline int |
David S. Miller | d33e455 | 2010-12-14 13:01:14 -0800 | [diff] [blame] | 229 | dst_metric_locked(const struct dst_entry *dst, int metric) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 230 | { |
| 231 | return dst_metric(dst, RTAX_LOCK) & (1<<metric); |
| 232 | } |
| 233 | |
Eldad Zack | 7f95e18 | 2012-06-16 15:14:49 +0200 | [diff] [blame] | 234 | static inline void dst_hold(struct dst_entry *dst) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 235 | { |
Eric Dumazet | 5635c10 | 2008-11-16 19:46:36 -0800 | [diff] [blame] | 236 | /* |
| 237 | * If your kernel compilation stops here, please check |
| 238 | * __pad_to_align_refcnt declaration in struct dst_entry |
| 239 | */ |
| 240 | BUILD_BUG_ON(offsetof(struct dst_entry, __refcnt) & 63); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 241 | atomic_inc(&dst->__refcnt); |
| 242 | } |
| 243 | |
Pavel Emelyanov | 03f49f3 | 2007-11-10 21:28:34 -0800 | [diff] [blame] | 244 | static inline void dst_use(struct dst_entry *dst, unsigned long time) |
| 245 | { |
| 246 | dst_hold(dst); |
| 247 | dst->__use++; |
| 248 | dst->lastuse = time; |
| 249 | } |
| 250 | |
Eric Dumazet | 7fee226 | 2010-05-11 23:19:48 +0000 | [diff] [blame] | 251 | static inline void dst_use_noref(struct dst_entry *dst, unsigned long time) |
| 252 | { |
| 253 | dst->__use++; |
| 254 | dst->lastuse = time; |
| 255 | } |
| 256 | |
Eldad Zack | 7f95e18 | 2012-06-16 15:14:49 +0200 | [diff] [blame] | 257 | static inline struct dst_entry *dst_clone(struct dst_entry *dst) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 258 | { |
| 259 | if (dst) |
| 260 | atomic_inc(&dst->__refcnt); |
| 261 | return dst; |
| 262 | } |
| 263 | |
Joe Perches | a4023dd | 2013-09-20 11:23:21 -0700 | [diff] [blame] | 264 | void dst_release(struct dst_entry *dst); |
Eric Dumazet | 7fee226 | 2010-05-11 23:19:48 +0000 | [diff] [blame] | 265 | |
| 266 | static inline void refdst_drop(unsigned long refdst) |
| 267 | { |
| 268 | if (!(refdst & SKB_DST_NOREF)) |
| 269 | dst_release((struct dst_entry *)(refdst & SKB_DST_PTRMASK)); |
| 270 | } |
| 271 | |
| 272 | /** |
| 273 | * skb_dst_drop - drops skb dst |
| 274 | * @skb: buffer |
| 275 | * |
| 276 | * Drops dst reference count if a reference was taken. |
| 277 | */ |
Eric Dumazet | adf3090 | 2009-06-02 05:19:30 +0000 | [diff] [blame] | 278 | static inline void skb_dst_drop(struct sk_buff *skb) |
| 279 | { |
Eric Dumazet | 7fee226 | 2010-05-11 23:19:48 +0000 | [diff] [blame] | 280 | if (skb->_skb_refdst) { |
| 281 | refdst_drop(skb->_skb_refdst); |
| 282 | skb->_skb_refdst = 0UL; |
| 283 | } |
| 284 | } |
| 285 | |
| 286 | static inline void skb_dst_copy(struct sk_buff *nskb, const struct sk_buff *oskb) |
| 287 | { |
| 288 | nskb->_skb_refdst = oskb->_skb_refdst; |
| 289 | if (!(nskb->_skb_refdst & SKB_DST_NOREF)) |
| 290 | dst_clone(skb_dst(nskb)); |
| 291 | } |
| 292 | |
| 293 | /** |
| 294 | * skb_dst_force - makes sure skb dst is refcounted |
| 295 | * @skb: buffer |
| 296 | * |
| 297 | * If dst is not yet refcounted, let's do it |
| 298 | */ |
| 299 | static inline void skb_dst_force(struct sk_buff *skb) |
| 300 | { |
| 301 | if (skb_dst_is_noref(skb)) { |
| 302 | WARN_ON(!rcu_read_lock_held()); |
| 303 | skb->_skb_refdst &= ~SKB_DST_NOREF; |
| 304 | dst_clone(skb_dst(skb)); |
| 305 | } |
Eric Dumazet | adf3090 | 2009-06-02 05:19:30 +0000 | [diff] [blame] | 306 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 307 | |
Eric Dumazet | d19d56d | 2010-05-17 22:36:55 -0700 | [diff] [blame] | 308 | |
| 309 | /** |
Eric Dumazet | 290b895 | 2010-09-27 00:33:35 +0000 | [diff] [blame] | 310 | * __skb_tunnel_rx - prepare skb for rx reinsert |
| 311 | * @skb: buffer |
| 312 | * @dev: tunnel device |
Nicolas Dichtel | ea23192 | 2013-09-02 15:34:58 +0200 | [diff] [blame] | 313 | * @net: netns for packet i/o |
Eric Dumazet | 290b895 | 2010-09-27 00:33:35 +0000 | [diff] [blame] | 314 | * |
| 315 | * After decapsulation, packet is going to re-enter (netif_rx()) our stack, |
| 316 | * so make some cleanups. (no accounting done) |
| 317 | */ |
Nicolas Dichtel | ea23192 | 2013-09-02 15:34:58 +0200 | [diff] [blame] | 318 | static inline void __skb_tunnel_rx(struct sk_buff *skb, struct net_device *dev, |
| 319 | struct net *net) |
Eric Dumazet | 290b895 | 2010-09-27 00:33:35 +0000 | [diff] [blame] | 320 | { |
| 321 | skb->dev = dev; |
Tom Herbert | bdeab99 | 2011-08-14 19:45:55 +0000 | [diff] [blame] | 322 | |
| 323 | /* |
Tom Herbert | 7539fad | 2013-12-15 22:12:18 -0800 | [diff] [blame] | 324 | * Clear hash so that we can recalulate the hash for the |
Tom Herbert | bdeab99 | 2011-08-14 19:45:55 +0000 | [diff] [blame] | 325 | * encapsulated packet, unless we have already determine the hash |
| 326 | * over the L4 4-tuple. |
| 327 | */ |
Tom Herbert | 7539fad | 2013-12-15 22:12:18 -0800 | [diff] [blame] | 328 | skb_clear_hash_if_not_l4(skb); |
Eric Dumazet | 290b895 | 2010-09-27 00:33:35 +0000 | [diff] [blame] | 329 | skb_set_queue_mapping(skb, 0); |
Nicolas Dichtel | ea23192 | 2013-09-02 15:34:58 +0200 | [diff] [blame] | 330 | skb_scrub_packet(skb, !net_eq(net, dev_net(dev))); |
Eric Dumazet | 290b895 | 2010-09-27 00:33:35 +0000 | [diff] [blame] | 331 | } |
| 332 | |
| 333 | /** |
Eric Dumazet | d19d56d | 2010-05-17 22:36:55 -0700 | [diff] [blame] | 334 | * skb_tunnel_rx - prepare skb for rx reinsert |
| 335 | * @skb: buffer |
| 336 | * @dev: tunnel device |
| 337 | * |
| 338 | * After decapsulation, packet is going to re-enter (netif_rx()) our stack, |
| 339 | * so make some cleanups, and perform accounting. |
Eric Dumazet | 290b895 | 2010-09-27 00:33:35 +0000 | [diff] [blame] | 340 | * Note: this accounting is not SMP safe. |
Eric Dumazet | d19d56d | 2010-05-17 22:36:55 -0700 | [diff] [blame] | 341 | */ |
Nicolas Dichtel | ea23192 | 2013-09-02 15:34:58 +0200 | [diff] [blame] | 342 | static inline void skb_tunnel_rx(struct sk_buff *skb, struct net_device *dev, |
| 343 | struct net *net) |
Eric Dumazet | d19d56d | 2010-05-17 22:36:55 -0700 | [diff] [blame] | 344 | { |
Eric Dumazet | d19d56d | 2010-05-17 22:36:55 -0700 | [diff] [blame] | 345 | /* TODO : stats should be SMP safe */ |
| 346 | dev->stats.rx_packets++; |
| 347 | dev->stats.rx_bytes += skb->len; |
Nicolas Dichtel | ea23192 | 2013-09-02 15:34:58 +0200 | [diff] [blame] | 348 | __skb_tunnel_rx(skb, dev, net); |
Eric Dumazet | d19d56d | 2010-05-17 22:36:55 -0700 | [diff] [blame] | 349 | } |
| 350 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 351 | /* Children define the path of the packet through the |
| 352 | * Linux networking. Thus, destinations are stackable. |
| 353 | */ |
| 354 | |
Steffen Klassert | 8764ab2 | 2010-06-04 01:57:38 +0000 | [diff] [blame] | 355 | static inline struct dst_entry *skb_dst_pop(struct sk_buff *skb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 356 | { |
Steffen Klassert | e433430 | 2011-03-15 21:09:32 +0000 | [diff] [blame] | 357 | struct dst_entry *child = dst_clone(skb_dst(skb)->child); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 358 | |
Steffen Klassert | 8764ab2 | 2010-06-04 01:57:38 +0000 | [diff] [blame] | 359 | skb_dst_drop(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 360 | return child; |
| 361 | } |
| 362 | |
Joe Perches | a4023dd | 2013-09-20 11:23:21 -0700 | [diff] [blame] | 363 | int dst_discard(struct sk_buff *skb); |
| 364 | void *dst_alloc(struct dst_ops *ops, struct net_device *dev, int initial_ref, |
| 365 | int initial_obsolete, unsigned short flags); |
| 366 | void __dst_free(struct dst_entry *dst); |
| 367 | struct dst_entry *dst_destroy(struct dst_entry *dst); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 368 | |
Eldad Zack | 7f95e18 | 2012-06-16 15:14:49 +0200 | [diff] [blame] | 369 | static inline void dst_free(struct dst_entry *dst) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 370 | { |
David S. Miller | f5b0a87 | 2012-07-19 12:31:33 -0700 | [diff] [blame] | 371 | if (dst->obsolete > 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 372 | return; |
| 373 | if (!atomic_read(&dst->__refcnt)) { |
| 374 | dst = dst_destroy(dst); |
| 375 | if (!dst) |
| 376 | return; |
| 377 | } |
| 378 | __dst_free(dst); |
| 379 | } |
| 380 | |
| 381 | static inline void dst_rcu_free(struct rcu_head *head) |
| 382 | { |
| 383 | struct dst_entry *dst = container_of(head, struct dst_entry, rcu_head); |
| 384 | dst_free(dst); |
| 385 | } |
| 386 | |
| 387 | static inline void dst_confirm(struct dst_entry *dst) |
| 388 | { |
David S. Miller | 5110effe | 2012-07-02 02:21:03 -0700 | [diff] [blame] | 389 | dst->pending_confirm = 1; |
| 390 | } |
Eric Dumazet | f2c31e3 | 2011-07-29 19:00:53 +0000 | [diff] [blame] | 391 | |
David S. Miller | 5110effe | 2012-07-02 02:21:03 -0700 | [diff] [blame] | 392 | static inline int dst_neigh_output(struct dst_entry *dst, struct neighbour *n, |
| 393 | struct sk_buff *skb) |
| 394 | { |
Eric Dumazet | 425f09a | 2012-08-07 02:19:56 +0000 | [diff] [blame] | 395 | const struct hh_cache *hh; |
David S. Miller | 5110effe | 2012-07-02 02:21:03 -0700 | [diff] [blame] | 396 | |
Eric Dumazet | 425f09a | 2012-08-07 02:19:56 +0000 | [diff] [blame] | 397 | if (dst->pending_confirm) { |
| 398 | unsigned long now = jiffies; |
| 399 | |
David S. Miller | 5110effe | 2012-07-02 02:21:03 -0700 | [diff] [blame] | 400 | dst->pending_confirm = 0; |
Eric Dumazet | 425f09a | 2012-08-07 02:19:56 +0000 | [diff] [blame] | 401 | /* avoid dirtying neighbour */ |
| 402 | if (n->confirmed != now) |
| 403 | n->confirmed = now; |
David S. Miller | 69cce1d | 2011-07-17 23:09:49 -0700 | [diff] [blame] | 404 | } |
David S. Miller | 5110effe | 2012-07-02 02:21:03 -0700 | [diff] [blame] | 405 | |
| 406 | hh = &n->hh; |
| 407 | if ((n->nud_state & NUD_CONNECTED) && hh->hh_len) |
| 408 | return neigh_hh_output(hh, skb); |
| 409 | else |
| 410 | return n->output(n, skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 411 | } |
| 412 | |
David S. Miller | d3aaeb3 | 2011-07-18 00:40:17 -0700 | [diff] [blame] | 413 | static inline struct neighbour *dst_neigh_lookup(const struct dst_entry *dst, const void *daddr) |
| 414 | { |
Zhouyi Zhou | aaa0c23 | 2013-03-14 17:21:50 +0000 | [diff] [blame] | 415 | struct neighbour *n = dst->ops->neigh_lookup(dst, NULL, daddr); |
| 416 | return IS_ERR(n) ? NULL : n; |
David S. Miller | f894cbf | 2012-07-02 21:52:24 -0700 | [diff] [blame] | 417 | } |
| 418 | |
| 419 | static inline struct neighbour *dst_neigh_lookup_skb(const struct dst_entry *dst, |
| 420 | struct sk_buff *skb) |
| 421 | { |
Zhouyi Zhou | aaa0c23 | 2013-03-14 17:21:50 +0000 | [diff] [blame] | 422 | struct neighbour *n = dst->ops->neigh_lookup(dst, skb, NULL); |
| 423 | return IS_ERR(n) ? NULL : n; |
David S. Miller | d3aaeb3 | 2011-07-18 00:40:17 -0700 | [diff] [blame] | 424 | } |
| 425 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 426 | static inline void dst_link_failure(struct sk_buff *skb) |
| 427 | { |
Eric Dumazet | adf3090 | 2009-06-02 05:19:30 +0000 | [diff] [blame] | 428 | struct dst_entry *dst = skb_dst(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 429 | if (dst && dst->ops && dst->ops->link_failure) |
| 430 | dst->ops->link_failure(skb); |
| 431 | } |
| 432 | |
| 433 | static inline void dst_set_expires(struct dst_entry *dst, int timeout) |
| 434 | { |
| 435 | unsigned long expires = jiffies + timeout; |
| 436 | |
| 437 | if (expires == 0) |
| 438 | expires = 1; |
| 439 | |
| 440 | if (dst->expires == 0 || time_before(expires, dst->expires)) |
| 441 | dst->expires = expires; |
| 442 | } |
| 443 | |
| 444 | /* Output packet to network from transport. */ |
| 445 | static inline int dst_output(struct sk_buff *skb) |
| 446 | { |
Eric Dumazet | adf3090 | 2009-06-02 05:19:30 +0000 | [diff] [blame] | 447 | return skb_dst(skb)->output(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 448 | } |
| 449 | |
| 450 | /* Input packet from network to transport. */ |
| 451 | static inline int dst_input(struct sk_buff *skb) |
| 452 | { |
Eric Dumazet | adf3090 | 2009-06-02 05:19:30 +0000 | [diff] [blame] | 453 | return skb_dst(skb)->input(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 454 | } |
| 455 | |
| 456 | static inline struct dst_entry *dst_check(struct dst_entry *dst, u32 cookie) |
| 457 | { |
| 458 | if (dst->obsolete) |
| 459 | dst = dst->ops->check(dst, cookie); |
| 460 | return dst; |
| 461 | } |
| 462 | |
Joe Perches | a4023dd | 2013-09-20 11:23:21 -0700 | [diff] [blame] | 463 | void dst_init(void); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 464 | |
Herbert Xu | 815f4e5 | 2007-12-12 10:36:59 -0800 | [diff] [blame] | 465 | /* Flags for xfrm_lookup flags argument. */ |
| 466 | enum { |
David S. Miller | 80c0bc9 | 2011-03-01 14:36:37 -0800 | [diff] [blame] | 467 | XFRM_LOOKUP_ICMP = 1 << 0, |
Herbert Xu | 815f4e5 | 2007-12-12 10:36:59 -0800 | [diff] [blame] | 468 | }; |
| 469 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 470 | struct flowi; |
| 471 | #ifndef CONFIG_XFRM |
David S. Miller | 452edd5 | 2011-03-02 13:27:41 -0800 | [diff] [blame] | 472 | static inline struct dst_entry *xfrm_lookup(struct net *net, |
| 473 | struct dst_entry *dst_orig, |
| 474 | const struct flowi *fl, struct sock *sk, |
| 475 | int flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 476 | { |
David S. Miller | 452edd5 | 2011-03-02 13:27:41 -0800 | [diff] [blame] | 477 | return dst_orig; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 478 | } |
Vlad Yasevich | e87b399 | 2013-10-15 22:01:29 -0400 | [diff] [blame] | 479 | |
| 480 | static inline struct xfrm_state *dst_xfrm(const struct dst_entry *dst) |
| 481 | { |
| 482 | return NULL; |
| 483 | } |
| 484 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 485 | #else |
Joe Perches | a4023dd | 2013-09-20 11:23:21 -0700 | [diff] [blame] | 486 | struct dst_entry *xfrm_lookup(struct net *net, struct dst_entry *dst_orig, |
| 487 | const struct flowi *fl, struct sock *sk, |
| 488 | int flags); |
Vlad Yasevich | e87b399 | 2013-10-15 22:01:29 -0400 | [diff] [blame] | 489 | |
| 490 | /* skb attached with this dst needs transformation if dst->xfrm is valid */ |
| 491 | static inline struct xfrm_state *dst_xfrm(const struct dst_entry *dst) |
| 492 | { |
| 493 | return dst->xfrm; |
| 494 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 495 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 496 | |
| 497 | #endif /* _NET_DST_H */ |