Phonet: deliver broadcast packets to broadcast sockets
authorRémi Denis-Courmont <remi.denis-courmont@nokia.com>
Wed, 14 Oct 2009 00:48:27 +0000 (00:48 +0000)
committerDavid S. Miller <davem@davemloft.net>
Wed, 14 Oct 2009 22:04:15 +0000 (15:04 -0700)
Signed-off-by: Rémi Denis-Courmont <remi.denis-courmont@nokia.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
include/net/phonet/phonet.h
net/phonet/af_phonet.c
net/phonet/socket.c

index d43f71b5ec004218f5eb969d15b8bd82ce143f9c..fdb05fa0346f95372f77952012cbefb3e9863bfc 100644 (file)
@@ -47,6 +47,7 @@ static inline struct pn_sock *pn_sk(struct sock *sk)
 extern const struct proto_ops phonet_dgram_ops;
 
 struct sock *pn_find_sock_by_sa(struct net *net, const struct sockaddr_pn *sa);
+void pn_deliver_sock_broadcast(struct net *net, struct sk_buff *skb);
 void phonet_get_local_port_range(int *min, int *max);
 void pn_sock_hash(struct sock *sk);
 void pn_sock_unhash(struct sock *sk);
index c711d58b4bb56cbca679da5e73a60c7e6feaac06..b113fe00c154667c0f97afdc2a9e7a91f8f7590e 100644 (file)
@@ -369,6 +369,12 @@ static int phonet_rcv(struct sk_buff *skb, struct net_device *dev,
 
        pn_skb_get_dst_sockaddr(skb, &sa);
 
+       /* check if this is broadcasted */
+       if (pn_sockaddr_get_addr(&sa) == PNADDR_BROADCAST) {
+               pn_deliver_sock_broadcast(net, skb);
+               goto out;
+       }
+
        /* check if we are the destination */
        if (phonet_address_lookup(net, pn_sockaddr_get_addr(&sa)) == 0) {
                /* Phonet packet input */
index aa5b5a972bff7a3e40700b8969e3b145bca428eb..8c84190f22debbe868c5eb6e5648aa4f09f23e29 100644 (file)
@@ -94,7 +94,28 @@ struct sock *pn_find_sock_by_sa(struct net *net, const struct sockaddr_pn *spn)
        spin_unlock_bh(&pnsocks.lock);
 
        return rval;
+}
+
+/* Deliver a broadcast packet (only in bottom-half) */
+void pn_deliver_sock_broadcast(struct net *net, struct sk_buff *skb)
+{
+       struct hlist_node *node;
+       struct sock *sknode;
+
+       spin_lock(&pnsocks.lock);
+       sk_for_each(sknode, node, &pnsocks.hlist) {
+               struct sk_buff *clone;
+
+               if (!net_eq(sock_net(sknode), net))
+                       continue;
+               if (!sock_flag(sknode, SOCK_BROADCAST))
+                       continue;
 
+               clone = skb_clone(skb, GFP_ATOMIC);
+               if (clone)
+                       sk_receive_skb(sknode, clone, 0);
+       }
+       spin_unlock(&pnsocks.lock);
 }
 
 void pn_sock_hash(struct sock *sk)