Skip to content

Commit

Permalink
Phonet: common socket glue
Browse files Browse the repository at this point in the history
This provides the socket API for the Phonet protocols family.

Signed-off-by: Remi Denis-Courmont <remi.denis-courmont@nokia.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Remi Denis-Courmont authored and davem330 committed Sep 23, 2008
1 parent 8fb3974 commit ba113a9
Show file tree
Hide file tree
Showing 5 changed files with 363 additions and 3 deletions.
3 changes: 3 additions & 0 deletions include/linux/phonet.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@
#define PNADDR_ANY 0
#define PNPORT_RESOURCE_ROUTING 0

/* ioctls */
#define SIOCPNGETOBJECT (SIOCPROTOPRIVATE + 0)

/* Phonet protocol header */
struct phonethdr {
__u8 pn_rdev;
Expand Down
23 changes: 23 additions & 0 deletions include/net/phonet/phonet.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,28 @@
*/
#define MAX_PHONET_HEADER 8

/*
* Every Phonet* socket has this structure first in its
* protocol-specific structure under name c.
*/
struct pn_sock {
struct sock sk;
u16 sobject;
u8 resource;
};

static inline struct pn_sock *pn_sk(struct sock *sk)
{
return (struct pn_sock *)sk;
}

extern const struct proto_ops phonet_dgram_ops;

struct sock *pn_find_sock_by_sa(const struct sockaddr_pn *sa);
void pn_sock_hash(struct sock *sk);
void pn_sock_unhash(struct sock *sk);
int pn_sock_get_port(struct sock *sk, unsigned short sport);

static inline struct phonethdr *pn_hdr(struct sk_buff *skb)
{
return (struct phonethdr *)skb_network_header(skb);
Expand Down Expand Up @@ -64,6 +86,7 @@ void pn_skb_get_dst_sockaddr(struct sk_buff *skb, struct sockaddr_pn *sa)

/* Protocols in Phonet protocol family. */
struct phonet_protocol {
const struct proto_ops *ops;
struct proto *prot;
int sock_type;
};
Expand Down
1 change: 1 addition & 0 deletions net/phonet/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ obj-$(CONFIG_PHONET) += phonet.o
phonet-objs := \
pn_dev.o \
pn_netlink.o \
socket.o \
af_phonet.o
28 changes: 25 additions & 3 deletions net/phonet/af_phonet.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ static inline void phonet_proto_put(struct phonet_protocol *pp);

static int pn_socket_create(struct net *net, struct socket *sock, int protocol)
{
struct sock *sk;
struct pn_sock *pn;
struct phonet_protocol *pnp;
int err;

Expand Down Expand Up @@ -69,8 +71,22 @@ static int pn_socket_create(struct net *net, struct socket *sock, int protocol)
goto out;
}

/* TODO: create and init the struct sock */
err = -EPROTONOSUPPORT;
sk = sk_alloc(net, PF_PHONET, GFP_KERNEL, pnp->prot);
if (sk == NULL) {
err = -ENOMEM;
goto out;
}

sock_init_data(sock, sk);
sock->state = SS_UNCONNECTED;
sock->ops = pnp->ops;
sk->sk_backlog_rcv = sk->sk_prot->backlog_rcv;
sk->sk_protocol = protocol;
pn = pn_sk(sk);
pn->sobject = 0;
pn->resource = 0;
sk->sk_prot->init(sk);
err = 0;

out:
phonet_proto_put(pnp);
Expand All @@ -94,6 +110,7 @@ static int phonet_rcv(struct sk_buff *skb, struct net_device *dev,
struct net_device *orig_dev)
{
struct phonethdr *ph;
struct sock *sk;
struct sockaddr_pn sa;
u16 len;

Expand All @@ -118,7 +135,12 @@ static int phonet_rcv(struct sk_buff *skb, struct net_device *dev,
if (pn_sockaddr_get_addr(&sa) == 0)
goto out; /* currently, we cannot be device 0 */

/* TODO: put packets to sockets backlog */
sk = pn_find_sock_by_sa(&sa);
if (sk == NULL)
goto out;

/* Push data to the socket (or other sockets connected to it). */
return sk_receive_skb(sk, skb, 0);

out:
kfree_skb(skb);
Expand Down
Loading

0 comments on commit ba113a9

Please sign in to comment.