*
* Version: $Id: af_packet.c,v 1.61 2002/02/08 03:57:19 davem Exp $
*
- * Authors: Ross Biro, <bir7@leland.Stanford.Edu>
+ * Authors: Ross Biro
* Fred N. van Kempen, <waltje@uWalt.NL.Mugnet.ORG>
* Alan Cox, <gw4pts@gw4pts.ampr.org>
*
static void packet_flush_mclist(struct sock *sk);
-struct packet_opt
-{
+struct packet_sock {
+ /* struct sock has to be the first member of packet_sock */
+ struct sock sk;
struct tpacket_stats stats;
#ifdef CONFIG_PACKET_MMAP
char * *pg_vec;
#ifdef CONFIG_PACKET_MMAP
-static inline char *packet_lookup_frame(struct packet_opt *po, unsigned int position)
+static inline char *packet_lookup_frame(struct packet_sock *po, unsigned int position)
{
unsigned int pg_vec_pos, frame_offset;
char *frame;
}
#endif
-#define pkt_sk(__sk) ((struct packet_opt *)(__sk)->sk_protinfo)
+static inline struct packet_sock *pkt_sk(struct sock *sk)
+{
+ return (struct packet_sock *)sk;
+}
static void packet_sock_destruct(struct sock *sk)
{
return;
}
- if (pkt_sk(sk))
- kfree(pkt_sk(sk));
atomic_dec(&packet_socks_nr);
#ifdef PACKET_REFCNT_DEBUG
printk(KERN_DEBUG "PACKET socket %p is free, %d are alive\n", sk, atomic_read(&packet_socks_nr));
{
struct sock *sk;
struct sockaddr_ll *sll;
- struct packet_opt *po;
+ struct packet_sock *po;
u8 * skb_head = skb->data;
int skb_len = skb->len;
unsigned snaplen;
static int tpacket_rcv(struct sk_buff *skb, struct net_device *dev, struct packet_type *pt)
{
struct sock *sk;
- struct packet_opt *po;
+ struct packet_sock *po;
struct sockaddr_ll *sll;
struct tpacket_hdr *h;
u8 * skb_head = skb->data;
*/
if (saddr == NULL) {
- struct packet_opt *po = pkt_sk(sk);
+ struct packet_sock *po = pkt_sk(sk);
ifindex = po->ifindex;
proto = po->num;
static int packet_release(struct socket *sock)
{
struct sock *sk = sock->sk;
- struct packet_opt *po;
+ struct packet_sock *po;
if (!sk)
return 0;
static int packet_do_bind(struct sock *sk, struct net_device *dev, int protocol)
{
- struct packet_opt *po = pkt_sk(sk);
+ struct packet_sock *po = pkt_sk(sk);
/*
* Detach an existing hook if present.
*/
return err;
}
+static struct proto packet_proto = {
+ .name = "PACKET",
+ .owner = THIS_MODULE,
+ .obj_size = sizeof(struct packet_sock),
+};
/*
* Create a packet of type SOCK_PACKET.
static int packet_create(struct socket *sock, int protocol)
{
struct sock *sk;
- struct packet_opt *po;
+ struct packet_sock *po;
int err;
if (!capable(CAP_NET_RAW))
sock->state = SS_UNCONNECTED;
err = -ENOBUFS;
- sk = sk_alloc(PF_PACKET, GFP_KERNEL, 1, NULL);
+ sk = sk_alloc(PF_PACKET, GFP_KERNEL, &packet_proto, 1);
if (sk == NULL)
goto out;
if (sock->type == SOCK_PACKET)
sock->ops = &packet_ops_spkt;
#endif
- sock_init_data(sock,sk);
- sk_set_owner(sk, THIS_MODULE);
+ sock_init_data(sock, sk);
- po = sk->sk_protinfo = kmalloc(sizeof(*po), GFP_KERNEL);
- if (!po)
- goto out_free;
- memset(po, 0, sizeof(*po));
+ po = pkt_sk(sk);
sk->sk_family = PF_PACKET;
po->num = protocol;
sk_add_node(sk, &packet_sklist);
write_unlock_bh(&packet_sklist_lock);
return(0);
-
-out_free:
- sk_free(sk);
out:
return err;
}
{
struct net_device *dev;
struct sock *sk = sock->sk;
- struct packet_opt *po = pkt_sk(sk);
+ struct packet_sock *po = pkt_sk(sk);
struct sockaddr_ll *sll = (struct sockaddr_ll*)uaddr;
if (peer)
static int packet_mc_add(struct sock *sk, struct packet_mreq *mreq)
{
- struct packet_opt *po = pkt_sk(sk);
+ struct packet_sock *po = pkt_sk(sk);
struct packet_mclist *ml, *i;
struct net_device *dev;
int err;
static void packet_flush_mclist(struct sock *sk)
{
- struct packet_opt *po = pkt_sk(sk);
+ struct packet_sock *po = pkt_sk(sk);
struct packet_mclist *ml;
if (!po->mclist)
{
int len;
struct sock *sk = sock->sk;
- struct packet_opt *po = pkt_sk(sk);
+ struct packet_sock *po = pkt_sk(sk);
if (level != SOL_PACKET)
return -ENOPROTOOPT;
read_lock(&packet_sklist_lock);
sk_for_each(sk, node, &packet_sklist) {
- struct packet_opt *po = pkt_sk(sk);
+ struct packet_sock *po = pkt_sk(sk);
switch (msg) {
case NETDEV_UNREGISTER:
poll_table *wait)
{
struct sock *sk = sock->sk;
- struct packet_opt *po = pkt_sk(sk);
+ struct packet_sock *po = pkt_sk(sk);
unsigned int mask = datagram_poll(file, sock, wait);
spin_lock_bh(&sk->sk_receive_queue.lock);
static int packet_set_ring(struct sock *sk, struct tpacket_req *req, int closing)
{
char **pg_vec = NULL;
- struct packet_opt *po = pkt_sk(sk);
+ struct packet_sock *po = pkt_sk(sk);
int was_running, num, order = 0;
int err = 0;
static int packet_mmap(struct file *file, struct socket *sock, struct vm_area_struct *vma)
{
struct sock *sk = sock->sk;
- struct packet_opt *po = pkt_sk(sk);
+ struct packet_sock *po = pkt_sk(sk);
unsigned long size;
unsigned long start;
int err = -EINVAL;
seq_puts(seq, "sk RefCnt Type Proto Iface R Rmem User Inode\n");
else {
struct sock *s = v;
- const struct packet_opt *po = pkt_sk(s);
+ const struct packet_sock *po = pkt_sk(s);
seq_printf(seq,
"%p %-6d %-4d %04x %-5d %1d %-6u %-6u %-6lu\n",
proc_net_remove("packet");
unregister_netdevice_notifier(&packet_netdev_notifier);
sock_unregister(PF_PACKET);
- return;
+ proto_unregister(&packet_proto);
}
static int __init packet_init(void)
{
+ int rc = proto_register(&packet_proto, 0);
+
+ if (rc != 0)
+ goto out;
+
sock_register(&packet_family_ops);
register_netdevice_notifier(&packet_netdev_notifier);
proc_net_fops_create("packet", 0, &packet_seq_fops);
-
- return 0;
+out:
+ return rc;
}
module_init(packet_init);