|
9 | 9 |
|
10 | 10 | #include <linux/netdevice.h> |
11 | 11 | #include <linux/skbuff.h> |
| 12 | +#include <net/gro_cells.h> |
12 | 13 | #include <net/gso.h> |
13 | 14 |
|
14 | | -#include "io.h" |
15 | 15 | #include "ovpnpriv.h" |
16 | 16 | #include "peer.h" |
| 17 | +#include "io.h" |
| 18 | +#include "netlink.h" |
| 19 | +#include "proto.h" |
17 | 20 | #include "udp.h" |
18 | 21 | #include "skb.h" |
19 | 22 | #include "socket.h" |
20 | 23 |
|
| 24 | +/* Called after decrypt to write the IP packet to the device. |
| 25 | + * This method is expected to manage/free the skb. |
| 26 | + */ |
| 27 | +static void ovpn_netdev_write(struct ovpn_peer *peer, struct sk_buff *skb) |
| 28 | +{ |
| 29 | + unsigned int pkt_len; |
| 30 | + int ret; |
| 31 | + |
| 32 | + /* we can't guarantee the packet wasn't corrupted before entering the |
| 33 | + * VPN, therefore we give other layers a chance to check that |
| 34 | + */ |
| 35 | + skb->ip_summed = CHECKSUM_NONE; |
| 36 | + |
| 37 | + /* skb hash for transport packet no longer valid after decapsulation */ |
| 38 | + skb_clear_hash(skb); |
| 39 | + |
| 40 | + /* post-decrypt scrub -- prepare to inject encapsulated packet onto the |
| 41 | + * interface, based on __skb_tunnel_rx() in dst.h |
| 42 | + */ |
| 43 | + skb->dev = peer->ovpn->dev; |
| 44 | + skb_set_queue_mapping(skb, 0); |
| 45 | + skb_scrub_packet(skb, true); |
| 46 | + |
| 47 | + skb_reset_network_header(skb); |
| 48 | + skb_reset_transport_header(skb); |
| 49 | + skb_reset_inner_headers(skb); |
| 50 | + |
| 51 | + /* cause packet to be "received" by the interface */ |
| 52 | + pkt_len = skb->len; |
| 53 | + ret = gro_cells_receive(&peer->ovpn->gro_cells, skb); |
| 54 | + if (likely(ret == NET_RX_SUCCESS)) |
| 55 | + /* update RX stats with the size of decrypted packet */ |
| 56 | + dev_dstats_rx_add(peer->ovpn->dev, pkt_len); |
| 57 | +} |
| 58 | + |
| 59 | +static void ovpn_decrypt_post(struct sk_buff *skb, int ret) |
| 60 | +{ |
| 61 | + struct ovpn_peer *peer = ovpn_skb_cb(skb)->peer; |
| 62 | + |
| 63 | + if (unlikely(ret < 0)) |
| 64 | + goto drop; |
| 65 | + |
| 66 | + ovpn_netdev_write(peer, skb); |
| 67 | + /* skb is passed to upper layer - don't free it */ |
| 68 | + skb = NULL; |
| 69 | +drop: |
| 70 | + if (unlikely(skb)) |
| 71 | + dev_dstats_rx_dropped(peer->ovpn->dev); |
| 72 | + ovpn_peer_put(peer); |
| 73 | + kfree_skb(skb); |
| 74 | +} |
| 75 | + |
| 76 | +/* RX path entry point: decrypt packet and forward it to the device */ |
| 77 | +void ovpn_recv(struct ovpn_peer *peer, struct sk_buff *skb) |
| 78 | +{ |
| 79 | + ovpn_skb_cb(skb)->peer = peer; |
| 80 | + ovpn_decrypt_post(skb, 0); |
| 81 | +} |
| 82 | + |
21 | 83 | static void ovpn_encrypt_post(struct sk_buff *skb, int ret) |
22 | 84 | { |
23 | 85 | struct ovpn_peer *peer = ovpn_skb_cb(skb)->peer; |
|
0 commit comments