Updated from Linux LTS 3.10.22 to 3.10.23
This commit is contained in:
@@ -244,11 +244,15 @@ static void __fanout_link(struct sock *sk, struct packet_sock *po);
|
||||
static void register_prot_hook(struct sock *sk)
|
||||
{
|
||||
struct packet_sock *po = pkt_sk(sk);
|
||||
|
||||
if (!po->running) {
|
||||
if (po->fanout)
|
||||
if (po->fanout) {
|
||||
__fanout_link(sk, po);
|
||||
else
|
||||
} else {
|
||||
dev_add_pack(&po->prot_hook);
|
||||
rcu_assign_pointer(po->cached_dev, po->prot_hook.dev);
|
||||
}
|
||||
|
||||
sock_hold(sk);
|
||||
po->running = 1;
|
||||
}
|
||||
@@ -266,10 +270,13 @@ static void __unregister_prot_hook(struct sock *sk, bool sync)
|
||||
struct packet_sock *po = pkt_sk(sk);
|
||||
|
||||
po->running = 0;
|
||||
if (po->fanout)
|
||||
if (po->fanout) {
|
||||
__fanout_unlink(sk, po);
|
||||
else
|
||||
} else {
|
||||
__dev_remove_pack(&po->prot_hook);
|
||||
RCU_INIT_POINTER(po->cached_dev, NULL);
|
||||
}
|
||||
|
||||
__sock_put(sk);
|
||||
|
||||
if (sync) {
|
||||
@@ -432,9 +439,9 @@ static void prb_shutdown_retire_blk_timer(struct packet_sock *po,
|
||||
|
||||
pkc = tx_ring ? &po->tx_ring.prb_bdqc : &po->rx_ring.prb_bdqc;
|
||||
|
||||
spin_lock(&rb_queue->lock);
|
||||
spin_lock_bh(&rb_queue->lock);
|
||||
pkc->delete_blk_timer = 1;
|
||||
spin_unlock(&rb_queue->lock);
|
||||
spin_unlock_bh(&rb_queue->lock);
|
||||
|
||||
prb_del_retire_blk_timer(pkc);
|
||||
}
|
||||
@@ -2043,12 +2050,24 @@ static int tpacket_fill_skb(struct packet_sock *po, struct sk_buff *skb,
|
||||
return tp_len;
|
||||
}
|
||||
|
||||
static struct net_device *packet_cached_dev_get(struct packet_sock *po)
|
||||
{
|
||||
struct net_device *dev;
|
||||
|
||||
rcu_read_lock();
|
||||
dev = rcu_dereference(po->cached_dev);
|
||||
if (dev)
|
||||
dev_hold(dev);
|
||||
rcu_read_unlock();
|
||||
|
||||
return dev;
|
||||
}
|
||||
|
||||
static int tpacket_snd(struct packet_sock *po, struct msghdr *msg)
|
||||
{
|
||||
struct sk_buff *skb;
|
||||
struct net_device *dev;
|
||||
__be16 proto;
|
||||
bool need_rls_dev = false;
|
||||
int err, reserve = 0;
|
||||
void *ph;
|
||||
struct sockaddr_ll *saddr = (struct sockaddr_ll *)msg->msg_name;
|
||||
@@ -2061,7 +2080,7 @@ static int tpacket_snd(struct packet_sock *po, struct msghdr *msg)
|
||||
mutex_lock(&po->pg_vec_lock);
|
||||
|
||||
if (saddr == NULL) {
|
||||
dev = po->prot_hook.dev;
|
||||
dev = packet_cached_dev_get(po);
|
||||
proto = po->num;
|
||||
addr = NULL;
|
||||
} else {
|
||||
@@ -2075,19 +2094,17 @@ static int tpacket_snd(struct packet_sock *po, struct msghdr *msg)
|
||||
proto = saddr->sll_protocol;
|
||||
addr = saddr->sll_addr;
|
||||
dev = dev_get_by_index(sock_net(&po->sk), saddr->sll_ifindex);
|
||||
need_rls_dev = true;
|
||||
}
|
||||
|
||||
err = -ENXIO;
|
||||
if (unlikely(dev == NULL))
|
||||
goto out;
|
||||
|
||||
reserve = dev->hard_header_len;
|
||||
|
||||
err = -ENETDOWN;
|
||||
if (unlikely(!(dev->flags & IFF_UP)))
|
||||
goto out_put;
|
||||
|
||||
reserve = dev->hard_header_len;
|
||||
|
||||
size_max = po->tx_ring.frame_size
|
||||
- (po->tp_hdrlen - sizeof(struct sockaddr_ll));
|
||||
|
||||
@@ -2164,8 +2181,7 @@ out_status:
|
||||
__packet_set_status(po, ph, status);
|
||||
kfree_skb(skb);
|
||||
out_put:
|
||||
if (need_rls_dev)
|
||||
dev_put(dev);
|
||||
dev_put(dev);
|
||||
out:
|
||||
mutex_unlock(&po->pg_vec_lock);
|
||||
return err;
|
||||
@@ -2203,7 +2219,6 @@ static int packet_snd(struct socket *sock,
|
||||
struct sk_buff *skb;
|
||||
struct net_device *dev;
|
||||
__be16 proto;
|
||||
bool need_rls_dev = false;
|
||||
unsigned char *addr;
|
||||
int err, reserve = 0;
|
||||
struct virtio_net_hdr vnet_hdr = { 0 };
|
||||
@@ -2219,7 +2234,7 @@ static int packet_snd(struct socket *sock,
|
||||
*/
|
||||
|
||||
if (saddr == NULL) {
|
||||
dev = po->prot_hook.dev;
|
||||
dev = packet_cached_dev_get(po);
|
||||
proto = po->num;
|
||||
addr = NULL;
|
||||
} else {
|
||||
@@ -2231,19 +2246,17 @@ static int packet_snd(struct socket *sock,
|
||||
proto = saddr->sll_protocol;
|
||||
addr = saddr->sll_addr;
|
||||
dev = dev_get_by_index(sock_net(sk), saddr->sll_ifindex);
|
||||
need_rls_dev = true;
|
||||
}
|
||||
|
||||
err = -ENXIO;
|
||||
if (dev == NULL)
|
||||
if (unlikely(dev == NULL))
|
||||
goto out_unlock;
|
||||
err = -ENETDOWN;
|
||||
if (unlikely(!(dev->flags & IFF_UP)))
|
||||
goto out_unlock;
|
||||
|
||||
if (sock->type == SOCK_RAW)
|
||||
reserve = dev->hard_header_len;
|
||||
|
||||
err = -ENETDOWN;
|
||||
if (!(dev->flags & IFF_UP))
|
||||
goto out_unlock;
|
||||
|
||||
if (po->has_vnet_hdr) {
|
||||
vnet_hdr_len = sizeof(vnet_hdr);
|
||||
|
||||
@@ -2377,15 +2390,14 @@ static int packet_snd(struct socket *sock,
|
||||
if (err > 0 && (err = net_xmit_errno(err)) != 0)
|
||||
goto out_unlock;
|
||||
|
||||
if (need_rls_dev)
|
||||
dev_put(dev);
|
||||
dev_put(dev);
|
||||
|
||||
return len;
|
||||
|
||||
out_free:
|
||||
kfree_skb(skb);
|
||||
out_unlock:
|
||||
if (dev && need_rls_dev)
|
||||
if (dev)
|
||||
dev_put(dev);
|
||||
out:
|
||||
return err;
|
||||
@@ -2605,6 +2617,7 @@ static int packet_create(struct net *net, struct socket *sock, int protocol,
|
||||
po = pkt_sk(sk);
|
||||
sk->sk_family = PF_PACKET;
|
||||
po->num = proto;
|
||||
RCU_INIT_POINTER(po->cached_dev, NULL);
|
||||
|
||||
sk->sk_destruct = packet_sock_destruct;
|
||||
sk_refcnt_debug_inc(sk);
|
||||
|
||||
@@ -113,6 +113,7 @@ struct packet_sock {
|
||||
unsigned int tp_loss:1;
|
||||
unsigned int tp_tx_has_off:1;
|
||||
unsigned int tp_tstamp;
|
||||
struct net_device __rcu *cached_dev;
|
||||
struct packet_type prot_hook ____cacheline_aligned_in_smp;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user