]> rtime.felk.cvut.cz Git - can-eth-gw.git/commitdiff
Cleanups, formatting, simplifications
authorMichal Sojka <sojkam1@fel.cvut.cz>
Wed, 29 Aug 2012 07:40:28 +0000 (09:40 +0200)
committerMichal Sojka <sojkam1@fel.cvut.cz>
Wed, 29 Aug 2012 07:40:28 +0000 (09:40 +0200)
kernel/canethgw.c

index 1d1e95ec6f7e38b67f78a6a01158bfea4fa2ad17..060cfa54345cf98134b5351b75dcb9b652c6fbff 100644 (file)
 
 MODULE_LICENSE("GPL");
 
-static int  cegw_udp_can(void *data);
+static int  cegw_udp2can(void *data);
 static void cegw_udp_send(struct socket *udp_sock, struct can_frame *cf,
-               struct in_addr ipaddr, u16 port);
-static int  cegw_can_udp(void *data);
+                         struct in_addr ipaddr, u16 port);
+static int  cegw_can2udp(void *data);
 static void cegw_can_send(struct socket *can_sock, struct can_frame *cf,
-               int ifindex);
+                         int ifindex);
 static int cegw_thread_start(void *data);
 static int cegw_thread_stop(void);
 
-enum __cegw_state
-{
+enum __cegw_state {
        CEGW_RUN,
        CEGW_STOP,
        CEGW_EXIT
 };
 
-struct cegw_rule
-{
+struct cegw_rule {
        int can_ifindex;
        struct in_addr eth_ip;
        unsigned short eth_port;
        struct hlist_node list;
 };
 
-struct cegw_setting
-{
+struct cegw_setting {
        struct in_addr eth_ip;
        unsigned short eth_port;
 };
 
+
 static int cegw_state = CEGW_STOP;
 static struct socket *can_sock = NULL, *udp_sock = NULL;
 static struct task_struct *eth_to_can = NULL, *can_to_eth = NULL;
@@ -64,7 +62,7 @@ static DEFINE_MUTEX(rule_can_eth_mutex);
 static DEFINE_MUTEX(cegw_mutex);
 
 static void cegw_udp_send(struct socket *udp_sock, struct can_frame *cf,
-               struct in_addr ipaddr, u16 port)
+                         struct in_addr ipaddr, u16 port)
 {
        struct msghdr mh;
        struct sockaddr_in addr;
@@ -83,6 +81,7 @@ static void cegw_udp_send(struct socket *udp_sock, struct can_frame *cf,
        vec.iov_base = cf;
        vec.iov_len = sizeof(*cf);
 
+       /* FIXME: Convert endianing of cf->can_id */
        kernel_sendmsg(udp_sock, &mh, &vec, 1, sizeof(*cf));
 }
 
@@ -109,11 +108,11 @@ static void cegw_can_send(struct socket* can_sock, struct can_frame* cf,
 }
 
 /**
- * cegw_udp_can - performs udp->can routing
+ * cegw_udp2can - performs udp->can routing
  *
  * This function is run as a thread.
  */
-static int cegw_udp_can(void *data)
+static int cegw_udp2can(void *data)
 {
        struct can_frame cf;
        struct kvec vec;
@@ -123,17 +122,9 @@ static int cegw_udp_can(void *data)
        int can_ifidx;
        int recv_size;
 
-       mh.msg_name = NULL;
-       mh.msg_namelen = 0;
-       mh.msg_iov = NULL;
-       mh.msg_iovlen = 0;
-       mh.msg_control = NULL;
-       mh.msg_controllen = 0;
-       mh.msg_flags = 0;
+       memset(&mh, 0, sizeof(mh));
 
-       while (1) {
-               if (cegw_state == CEGW_STOP)
-                       break;
+       while (cegw_state != CEGW_STOP) {
                vec.iov_base = &cf;
                vec.iov_len = sizeof(cf);
                recv_size = kernel_recvmsg(udp_sock, &mh, &vec, 1,
@@ -144,6 +135,7 @@ static int cegw_udp_can(void *data)
                else if (recv_size < 0)
                        return -1;
 
+               /* FIXME: Convert endianing of cf.can_id */
                mutex_lock(&rule_eth_can_mutex);
                hlist_for_each_entry(rule, pos, &rule_eth_can, list) {
                        can_ifidx = rule->can_ifindex;
@@ -157,9 +149,11 @@ static int cegw_udp_can(void *data)
 }
 
 /**
- * cegw_can_udp - performs can->udp routing
+ * cegw_can2udp - performs can->udp routing
+ *
+ * Runs as a thread.
  */
-static int cegw_can_udp(void* data)
+static int cegw_can2udp(void* data)
 {
        struct msghdr mh;
        struct kvec vec;
@@ -177,9 +171,7 @@ static int cegw_can_udp(void* data)
        mh.msg_controllen = 0;
        mh.msg_flags = 0;
 
-       while (1) {
-               if (cegw_state == CEGW_STOP)
-                       break;
+       while (cegw_state != CEGW_STOP) {
                vec.iov_base = &cf;
                vec.iov_len = sizeof(cf);
 
@@ -534,7 +526,7 @@ static int cegw_thread_start(void *data)
        /* start threads */
        cegw_state = CEGW_RUN;
 
-       eth_to_can = kthread_create(cegw_udp_can, NULL, "canethgw");
+       eth_to_can = kthread_create(cegw_udp2can, NULL, "canethgw");
        if (IS_ERR(eth_to_can)) {
                cegw_state = CEGW_STOP;
                sock_release(udp_sock);
@@ -544,7 +536,7 @@ static int cegw_thread_start(void *data)
        get_task_struct(eth_to_can);
        wake_up_process(eth_to_can);
 
-       can_to_eth = kthread_create(cegw_can_udp, NULL, "canethgw");
+       can_to_eth = kthread_create(cegw_can2udp, NULL, "canethgw");
        if (IS_ERR(can_to_eth)) {
                cegw_state = CEGW_STOP;
                kernel_sock_shutdown(udp_sock, SHUT_RDWR);