]> rtime.felk.cvut.cz Git - socketcan-devel.git/commitdiff
Remove struct raw_opt and bcm_opt and integrate them into
authorthuermann <thuermann@030b6a49-0b11-0410-94ab-b0dab22257f2>
Thu, 21 Jun 2007 10:29:54 +0000 (10:29 +0000)
committerthuermann <thuermann@030b6a49-0b11-0410-94ab-b0dab22257f2>
Thu, 21 Jun 2007 10:29:54 +0000 (10:29 +0000)
struct raw_scok resp. struct bcm_sock directly.
Add (untested) support for kernels < 2.6.12.

git-svn-id: svn://svn.berlios.de//socketcan/trunk@384 030b6a49-0b11-0410-94ab-b0dab22257f2

kernel/2.6/net/can/bcm.c
kernel/2.6/net/can/raw.c

index 6bb52a4e2f76d02f2809924776c13d37c224e4b0..21cbdb8a88c327e6f0e74fd4311e376ee97c885f 100644 (file)
@@ -113,17 +113,6 @@ struct bcm_op {
        struct net_device *rx_reg_dev;
 };
 
-struct bcm_opt {
-       int bound;
-       int ifindex;
-       struct notifier_block notifier;
-       struct list_head rx_ops;
-       struct list_head tx_ops;
-       unsigned long dropped_usr_msgs;
-       struct proc_dir_entry *bcm_proc_read;
-       char procname [9]; /* pointer printed in ASCII with \0 */
-};
-
 static struct proc_dir_entry *proc_dir = NULL;
 
 #ifdef CONFIG_CAN_BCM_USER
@@ -132,22 +121,30 @@ static struct proc_dir_entry *proc_dir = NULL;
 #define BCM_CAP CAP_NET_RAW
 #endif
 
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,12)
 struct bcm_sock {
-       struct sock    sk;
-       struct bcm_opt opt;
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,12)
+       struct sock sk;
+#else
+       struct sock *sk;
+#endif
+       int bound;
+       int ifindex;
+       struct notifier_block notifier;
+       struct list_head rx_ops;
+       struct list_head tx_ops;
+       unsigned long dropped_usr_msgs;
+       struct proc_dir_entry *bcm_proc_read;
+       char procname [9]; /* pointer printed in ASCII with \0 */
 };
 
-static inline struct bcm_opt *bcm_sk(const struct sock *sk)
+static inline struct bcm_sock *bcm_sk(const struct sock *sk)
 {
-       return &((struct bcm_sock *)sk)->opt;
-}
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,12)
+       return (struct bcm_sock *)sk;
 #else
-static inline struct bcm_opt *bcm_sk(const struct sock *sk)
-{
-       return (struct bcm_opt *)sk->sk_protinfo;
-}
+       return (struct bcm_sock *)sk->sk_protinfo;
 #endif
+}
 
 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,14)
 static void *kzalloc(size_t size, unsigned int __nocast flags)
@@ -234,7 +231,7 @@ static int bcm_read_proc(char *page, char **start, off_t off,
 {
        int len = 0;
        struct sock *sk = (struct sock *)data;
-       struct bcm_opt *bo = bcm_sk(sk);
+       struct bcm_sock *bo = bcm_sk(sk);
        struct bcm_op *op;
 
        len += snprintf(page + len, PAGE_SIZE - len, ">>> socket %p",
@@ -417,7 +414,7 @@ static void bcm_send_to_user(struct bcm_op *op, struct bcm_msg_head *head,
 
        err = sock_queue_rcv_skb(sk, skb);
        if (err < 0) {
-               struct bcm_opt *bo = bcm_sk(sk);
+               struct bcm_sock *bo = bcm_sk(sk);
 
                DBG("sock_queue_rcv_skb failed: %d\n", err);
                kfree_skb(skb);
@@ -935,7 +932,7 @@ static int bcm_read_op(struct list_head *ops, struct bcm_msg_head *msg_head,
 static int bcm_tx_setup(struct bcm_msg_head *msg_head, struct msghdr *msg,
                        int ifindex, struct sock *sk)
 {
-       struct bcm_opt *bo = bcm_sk(sk);
+       struct bcm_sock *bo = bcm_sk(sk);
        struct bcm_op *op;
        int i, err;
 
@@ -1116,7 +1113,7 @@ static int bcm_tx_setup(struct bcm_msg_head *msg_head, struct msghdr *msg,
 static int bcm_rx_setup(struct bcm_msg_head *msg_head, struct msghdr *msg,
                        int ifindex, struct sock *sk)
 {
-       struct bcm_opt *bo = bcm_sk(sk);
+       struct bcm_sock *bo = bcm_sk(sk);
        struct bcm_op *op;
        int do_rx_register;
        int err;
@@ -1388,7 +1385,7 @@ static int bcm_sendmsg(struct kiocb *iocb, struct socket *sock,
                       struct msghdr *msg, size_t size)
 {
        struct sock *sk = sock->sk;
-       struct bcm_opt *bo = bcm_sk(sk);
+       struct bcm_sock *bo = bcm_sk(sk);
        int ifindex = bo->ifindex; /* default ifindex for this bcm_op */
        struct bcm_msg_head msg_head;
        int ret; /* read bytes or error codes as return value */
@@ -1500,12 +1497,11 @@ static int bcm_notifier(struct notifier_block *nb, unsigned long msg,
                        void *data)
 {
        struct net_device *dev = (struct net_device *)data;
-       struct bcm_opt *bo = container_of(nb, struct bcm_opt, notifier);
+       struct bcm_sock *bo = container_of(nb, struct bcm_sock, notifier);
 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,12)
-       struct bcm_sock *bs = container_of(bo, struct bcm_sock, opt);
-       struct sock *sk = &bs->sk;
+       struct sock *sk = &bo->sk;
 #else
-#error TODO (if needed): Notifier support for Kernel Versions < 2.6.12
+       struct sock *sk = bo->sk;
 #endif
        struct bcm_op *op;
        int notify_enodev = 0;
@@ -1558,8 +1554,11 @@ static int bcm_notifier(struct notifier_block *nb, unsigned long msg,
  */
 static int bcm_init(struct sock *sk)
 {
-       struct bcm_opt *bo = bcm_sk(sk);
+       struct bcm_sock *bo = bcm_sk(sk);
 
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,12)
+       bo->sk               = sk;
+#endif
        bo->bound            = 0;
        bo->ifindex          = 0;
        bo->dropped_usr_msgs = 0;
@@ -1582,7 +1581,7 @@ static int bcm_init(struct sock *sk)
 static int bcm_release(struct socket *sock)
 {
        struct sock *sk = sock->sk;
-       struct bcm_opt *bo = bcm_sk(sk);
+       struct bcm_sock *bo = bcm_sk(sk);
        struct bcm_op *op, *next;
 
        DBG("socket %p, sk %p\n", sock, sk);
@@ -1649,7 +1648,7 @@ static int bcm_connect(struct socket *sock, struct sockaddr *uaddr, int len,
 {
        struct sockaddr_can *addr = (struct sockaddr_can *)uaddr;
        struct sock *sk = sock->sk;
-       struct bcm_opt *bo = bcm_sk(sk);
+       struct bcm_sock *bo = bcm_sk(sk);
 
        if (bo->bound)
                return -EISCONN;
@@ -1789,7 +1788,7 @@ static struct can_proto bcm_can_proto = {
        .capability = BCM_CAP,
        .ops        = &bcm_ops,
        .owner      = THIS_MODULE,
-       .obj_size   = sizeof(struct bcm_opt),
+       .obj_size   = sizeof(struct bcm_sock),
        .init       = bcm_init,
 };
 #endif
index 2f322e01afab605143e1497e3477c2406421f8d0..ad3deb91ab14c56d25715c3c32249ce3f9bc286d 100644 (file)
@@ -90,7 +90,12 @@ MODULE_PARM_DESC(debug, "debug print mask: 1:debug, 2:frames, 4:skbs");
  * storing the single filter in dfilter, to avoid using dynamic memory.
  */
 
-struct raw_opt {
+struct raw_sock {
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,12)
+       struct sock sk;
+#else
+       struct sock *sk;
+#endif
        int bound;
        int ifindex;
        struct notifier_block notifier;
@@ -102,27 +107,19 @@ struct raw_opt {
        can_err_mask_t err_mask;
 };
 
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,12)
-struct raw_sock {
-       struct sock    sk;
-       struct raw_opt opt;
-};
-
-static inline struct raw_opt *raw_sk(const struct sock *sk)
+static inline struct raw_sock *raw_sk(const struct sock *sk)
 {
-       return &((struct raw_sock *)sk)->opt;
-}
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,12)
+       return (struct raw_sock *)sk;
 #else
-static inline struct raw_opt *raw_sk(const struct sock *sk)
-{
-       return (struct raw_opt *)sk->sk_protinfo;
-}
+       return (struct raw_sock *)sk->sk_protinfo;
 #endif
+}
 
 static void raw_rcv(struct sk_buff *skb, void *data)
 {
        struct sock *sk = (struct sock*)data;
-       struct raw_opt *ro = raw_sk(sk);
+       struct raw_sock *ro = raw_sk(sk);
        struct sockaddr_can *addr;
        int error;
 
@@ -153,7 +150,7 @@ static void raw_rcv(struct sk_buff *skb, void *data)
 
 static void raw_enable_filters(struct net_device *dev, struct sock *sk)
 {
-       struct raw_opt *ro = raw_sk(sk);
+       struct raw_sock *ro = raw_sk(sk);
        struct can_filter *filter = ro->filter;
        int i;
 
@@ -169,7 +166,7 @@ static void raw_enable_filters(struct net_device *dev, struct sock *sk)
 
 static void raw_enable_errfilter(struct net_device *dev, struct sock *sk)
 {
-       struct raw_opt *ro = raw_sk(sk);
+       struct raw_sock *ro = raw_sk(sk);
 
        if (ro->err_mask)
                can_rx_register(dev, 0, ro->err_mask | CAN_ERR_FLAG,
@@ -178,7 +175,7 @@ static void raw_enable_errfilter(struct net_device *dev, struct sock *sk)
 
 static void raw_disable_filters(struct net_device *dev, struct sock *sk)
 {
-       struct raw_opt *ro = raw_sk(sk);
+       struct raw_sock *ro = raw_sk(sk);
        struct can_filter *filter = ro->filter;
        int i;
 
@@ -194,7 +191,7 @@ static void raw_disable_filters(struct net_device *dev, struct sock *sk)
 
 static void raw_disable_errfilter(struct net_device *dev, struct sock *sk)
 {
-       struct raw_opt *ro = raw_sk(sk);
+       struct raw_sock *ro = raw_sk(sk);
 
        if (ro->err_mask)
                can_rx_unregister(dev, 0, ro->err_mask | CAN_ERR_FLAG,
@@ -205,12 +202,11 @@ static int raw_notifier(struct notifier_block *nb,
                        unsigned long msg, void *data)
 {
        struct net_device *dev = (struct net_device *)data;
-       struct raw_opt *ro = container_of(nb, struct raw_opt, notifier);
+       struct raw_sock *ro = container_of(nb, struct raw_sock, notifier);
 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,12)
-       struct raw_sock *rs = container_of(ro, struct raw_sock, opt);
-       struct sock *sk = &rs->sk;
+       struct sock *sk = &ro->sk;
 #else
-#error TODO (if needed): Notifier support for Kernel Versions < 2.6.12
+       struct sock *sk = ro->sk;
 #endif
 
        DBG("msg %ld for dev %p (%s idx %d) sk %p ro->ifindex %d\n",
@@ -257,8 +253,11 @@ static int raw_notifier(struct notifier_block *nb,
 
 static int raw_init(struct sock *sk)
 {
-       struct raw_opt *ro = raw_sk(sk);
+       struct raw_sock *ro = raw_sk(sk);
 
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,12)
+       ro->sk               = sk;
+#endif
        ro->bound            = 0;
        ro->ifindex          = 0;
 
@@ -283,7 +282,7 @@ static int raw_init(struct sock *sk)
 static int raw_release(struct socket *sock)
 {
        struct sock *sk = sock->sk;
-       struct raw_opt *ro = raw_sk(sk);
+       struct raw_sock *ro = raw_sk(sk);
 
        DBG("socket %p, sk %p, refcnt %d\n", sock, sk,
            atomic_read(&sk->sk_refcnt));
@@ -324,7 +323,7 @@ static int raw_bind(struct socket *sock, struct sockaddr *uaddr, int len)
 {
        struct sockaddr_can *addr = (struct sockaddr_can *)uaddr;
        struct sock *sk = sock->sk;
-       struct raw_opt *ro = raw_sk(sk);
+       struct raw_sock *ro = raw_sk(sk);
        int err = 0;
        int notify_enetdown = 0;
 
@@ -404,7 +403,7 @@ static int raw_getname(struct socket *sock, struct sockaddr *uaddr,
 {
        struct sockaddr_can *addr = (struct sockaddr_can *)uaddr;
        struct sock *sk = sock->sk;
-       struct raw_opt *ro = raw_sk(sk);
+       struct raw_sock *ro = raw_sk(sk);
 
        if (peer)
                return -EOPNOTSUPP;
@@ -432,7 +431,7 @@ static int raw_setsockopt(struct socket *sock, int level, int optname,
                          char __user *optval, int optlen)
 {
        struct sock *sk = sock->sk;
-       struct raw_opt *ro = raw_sk(sk);
+       struct raw_sock *ro = raw_sk(sk);
        struct can_filter *filter = NULL;  /* dyn. alloc'ed filters */
        struct can_filter sfilter;         /* single filter */
        struct net_device *dev = NULL;
@@ -563,7 +562,7 @@ static int raw_getsockopt(struct socket *sock, int level, int optname,
                          char __user *optval, int __user *optlen)
 {
        struct sock *sk = sock->sk;
-       struct raw_opt *ro = raw_sk(sk);
+       struct raw_sock *ro = raw_sk(sk);
        int len;
        void *val;
        int err = 0;
@@ -625,7 +624,7 @@ static int raw_sendmsg(struct kiocb *iocb, struct socket *sock,
                       struct msghdr *msg, size_t size)
 {
        struct sock *sk = sock->sk;
-       struct raw_opt *ro = raw_sk(sk);
+       struct raw_sock *ro = raw_sk(sk);
        struct sk_buff *skb;
        struct net_device *dev;
        int ifindex;
@@ -764,7 +763,7 @@ static struct can_proto raw_can_proto = {
        .capability = RAW_CAP,
        .ops        = &raw_ops,
        .owner      = THIS_MODULE,
-       .obj_size   = sizeof(struct raw_opt),
+       .obj_size   = sizeof(struct raw_sock),
        .init       = raw_init,
 };
 #endif