Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 111775
b: refs/heads/master
c: ba113a9
h: refs/heads/master
i:
  111773: f1c5992
  111771: 268bcc4
  111767: 336fbf0
  111759: f2f4105
  111743: 3a40b7e
v: v3
  • Loading branch information
Remi Denis-Courmont authored and David S. Miller committed Sep 23, 2008
1 parent 1647a2d commit d1e9b4e
Show file tree
Hide file tree
Showing 6 changed files with 364 additions and 4 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 8fb397406f6470f79040c41eec49af20900a9e3b
refs/heads/master: ba113a94b7503ee23ffe819e7045134b0c1d31de
3 changes: 3 additions & 0 deletions trunk/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 trunk/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 trunk/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 trunk/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 d1e9b4e

Please sign in to comment.