[PATCH] uml: multicast driver cleanup

Byte-swapping of the port and IP address passed in to the multicast driver by
the user used to happen in different places, which was a bug in itself. The
port also was swapped before being printk-ed, which led to a misleading
message. This patch moves the port swapping to the same place as the IP
address swapping. It also cleans up the error paths of mcast_open.

Signed-off-by: Jeff Dike <jdike@addtoit.com>
Cc: <viro@parcelfarce.linux.theplanet.co.uk>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>

authored by Jeff Dike and committed by Linus Torvalds 7c00c31f 060e3522

+16 -35
+1 -3
arch/um/drivers/mcast_kern.c
··· 73 struct mcast_init *init = data; 74 char *port_str = NULL, *ttl_str = NULL, *remain; 75 char *last; 76 - int n; 77 78 *init = ((struct mcast_init) 79 { .addr = "239.192.168.1", ··· 88 } 89 90 if(port_str != NULL){ 91 - n = simple_strtoul(port_str, &last, 10); 92 if((*last != '\0') || (last == port_str)){ 93 printk(KERN_ERR "mcast_setup - Bad port : '%s'\n", 94 port_str); 95 return(0); 96 } 97 - init->port = htons(n); 98 } 99 100 if(ttl_str != NULL){
··· 73 struct mcast_init *init = data; 74 char *port_str = NULL, *ttl_str = NULL, *remain; 75 char *last; 76 77 *init = ((struct mcast_init) 78 { .addr = "239.192.168.1", ··· 89 } 90 91 if(port_str != NULL){ 92 + init->port = simple_strtoul(port_str, &last, 10); 93 if((*last != '\0') || (last == port_str)){ 94 printk(KERN_ERR "mcast_setup - Bad port : '%s'\n", 95 port_str); 96 return(0); 97 } 98 } 99 100 if(ttl_str != NULL){
+15 -32
arch/um/drivers/mcast_user.c
··· 38 } 39 sin->sin_family = AF_INET; 40 sin->sin_addr.s_addr = in_aton(addr); 41 - sin->sin_port = port; 42 return(sin); 43 } 44 ··· 55 struct mcast_data *pri = data; 56 struct sockaddr_in *sin = pri->mcast_addr; 57 struct ip_mreq mreq; 58 - int fd, yes = 1; 59 60 61 - if ((sin->sin_addr.s_addr == 0) || (sin->sin_port == 0)) { 62 - fd = -EINVAL; 63 goto out; 64 - } 65 66 fd = socket(AF_INET, SOCK_DGRAM, 0); 67 if (fd < 0){ 68 printk("mcast_open : data socket failed, errno = %d\n", 69 errno); 70 - fd = -ENOMEM; 71 goto out; 72 } 73 74 if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(yes)) < 0) { 75 printk("mcast_open: SO_REUSEADDR failed, errno = %d\n", 76 errno); 77 - os_close_file(fd); 78 - fd = -EINVAL; 79 - goto out; 80 } 81 82 /* set ttl according to config */ ··· 81 sizeof(pri->ttl)) < 0) { 82 printk("mcast_open: IP_MULTICAST_TTL failed, error = %d\n", 83 errno); 84 - os_close_file(fd); 85 - fd = -EINVAL; 86 - goto out; 87 } 88 89 /* set LOOP, so data does get fed back to local sockets */ 90 if (setsockopt(fd, SOL_IP, IP_MULTICAST_LOOP, &yes, sizeof(yes)) < 0) { 91 printk("mcast_open: IP_MULTICAST_LOOP failed, error = %d\n", 92 errno); 93 - os_close_file(fd); 94 - fd = -EINVAL; 95 - goto out; 96 } 97 98 /* bind socket to mcast address */ 99 if (bind(fd, (struct sockaddr *) sin, sizeof(*sin)) < 0) { 100 printk("mcast_open : data bind failed, errno = %d\n", errno); 101 - os_close_file(fd); 102 - fd = -EINVAL; 103 - goto out; 104 } 105 106 /* subscribe to the multicast group */ ··· 108 "interface on the host.\n"); 109 printk("eth0 should be configured in order to use the " 110 "multicast transport.\n"); 111 - os_close_file(fd); 112 - fd = -EINVAL; 113 } 114 115 out: 116 - return(fd); 117 } 118 119 static void mcast_close(int fd, void *data) ··· 158 .delete_address = NULL, 159 .max_packet = MAX_PACKET - ETH_HEADER_OTHER 160 }; 161 - 162 - /* 163 - * Overrides for Emacs so that we follow Linus's tabbing style. 164 - * Emacs will notice this stuff at the end of the file and automatically 165 - * adjust the settings for this buffer only. This must remain at the end 166 - * of the file. 167 - * --------------------------------------------------------------------------- 168 - * Local variables: 169 - * c-file-style: "linux" 170 - * End: 171 - */
··· 38 } 39 sin->sin_family = AF_INET; 40 sin->sin_addr.s_addr = in_aton(addr); 41 + sin->sin_port = htons(port); 42 return(sin); 43 } 44 ··· 55 struct mcast_data *pri = data; 56 struct sockaddr_in *sin = pri->mcast_addr; 57 struct ip_mreq mreq; 58 + int fd = -EINVAL, yes = 1, err = -EINVAL;; 59 60 61 + if ((sin->sin_addr.s_addr == 0) || (sin->sin_port == 0)) 62 goto out; 63 64 fd = socket(AF_INET, SOCK_DGRAM, 0); 65 + 66 if (fd < 0){ 67 printk("mcast_open : data socket failed, errno = %d\n", 68 errno); 69 + fd = -errno; 70 goto out; 71 } 72 73 if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(yes)) < 0) { 74 printk("mcast_open: SO_REUSEADDR failed, errno = %d\n", 75 errno); 76 + goto out_close; 77 } 78 79 /* set ttl according to config */ ··· 84 sizeof(pri->ttl)) < 0) { 85 printk("mcast_open: IP_MULTICAST_TTL failed, error = %d\n", 86 errno); 87 + goto out_close; 88 } 89 90 /* set LOOP, so data does get fed back to local sockets */ 91 if (setsockopt(fd, SOL_IP, IP_MULTICAST_LOOP, &yes, sizeof(yes)) < 0) { 92 printk("mcast_open: IP_MULTICAST_LOOP failed, error = %d\n", 93 errno); 94 + goto out_close; 95 } 96 97 /* bind socket to mcast address */ 98 if (bind(fd, (struct sockaddr *) sin, sizeof(*sin)) < 0) { 99 printk("mcast_open : data bind failed, errno = %d\n", errno); 100 + goto out_close; 101 } 102 103 /* subscribe to the multicast group */ ··· 117 "interface on the host.\n"); 118 printk("eth0 should be configured in order to use the " 119 "multicast transport.\n"); 120 + goto out_close; 121 } 122 123 out: 124 + return fd; 125 + 126 + out_close: 127 + os_close_file(fd); 128 + return err; 129 } 130 131 static void mcast_close(int fd, void *data) ··· 164 .delete_address = NULL, 165 .max_packet = MAX_PACKET - ETH_HEADER_OTHER 166 };