Commit 4d52cfbe authored by Eric Dumazet's avatar Eric Dumazet Committed by David S. Miller

net: ipv4/ip_sockglue.c cleanups

Pure cleanups
Signed-off-by: default avatarEric Dumazet <eric.dumazet@gmail.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent dae9de8e
...@@ -157,38 +157,39 @@ void ip_cmsg_recv(struct msghdr *msg, struct sk_buff *skb) ...@@ -157,38 +157,39 @@ void ip_cmsg_recv(struct msghdr *msg, struct sk_buff *skb)
/* Ordered by supposed usage frequency */ /* Ordered by supposed usage frequency */
if (flags & 1) if (flags & 1)
ip_cmsg_recv_pktinfo(msg, skb); ip_cmsg_recv_pktinfo(msg, skb);
if ((flags>>=1) == 0) if ((flags >>= 1) == 0)
return; return;
if (flags & 1) if (flags & 1)
ip_cmsg_recv_ttl(msg, skb); ip_cmsg_recv_ttl(msg, skb);
if ((flags>>=1) == 0) if ((flags >>= 1) == 0)
return; return;
if (flags & 1) if (flags & 1)
ip_cmsg_recv_tos(msg, skb); ip_cmsg_recv_tos(msg, skb);
if ((flags>>=1) == 0) if ((flags >>= 1) == 0)
return; return;
if (flags & 1) if (flags & 1)
ip_cmsg_recv_opts(msg, skb); ip_cmsg_recv_opts(msg, skb);
if ((flags>>=1) == 0) if ((flags >>= 1) == 0)
return; return;
if (flags & 1) if (flags & 1)
ip_cmsg_recv_retopts(msg, skb); ip_cmsg_recv_retopts(msg, skb);
if ((flags>>=1) == 0) if ((flags >>= 1) == 0)
return; return;
if (flags & 1) if (flags & 1)
ip_cmsg_recv_security(msg, skb); ip_cmsg_recv_security(msg, skb);
if ((flags>>=1) == 0) if ((flags >>= 1) == 0)
return; return;
if (flags & 1) if (flags & 1)
ip_cmsg_recv_dstaddr(msg, skb); ip_cmsg_recv_dstaddr(msg, skb);
} }
EXPORT_SYMBOL(ip_cmsg_recv);
int ip_cmsg_send(struct net *net, struct msghdr *msg, struct ipcm_cookie *ipc) int ip_cmsg_send(struct net *net, struct msghdr *msg, struct ipcm_cookie *ipc)
{ {
...@@ -203,7 +204,8 @@ int ip_cmsg_send(struct net *net, struct msghdr *msg, struct ipcm_cookie *ipc) ...@@ -203,7 +204,8 @@ int ip_cmsg_send(struct net *net, struct msghdr *msg, struct ipcm_cookie *ipc)
switch (cmsg->cmsg_type) { switch (cmsg->cmsg_type) {
case IP_RETOPTS: case IP_RETOPTS:
err = cmsg->cmsg_len - CMSG_ALIGN(sizeof(struct cmsghdr)); err = cmsg->cmsg_len - CMSG_ALIGN(sizeof(struct cmsghdr));
err = ip_options_get(net, &ipc->opt, CMSG_DATA(cmsg), err < 40 ? err : 40); err = ip_options_get(net, &ipc->opt, CMSG_DATA(cmsg),
err < 40 ? err : 40);
if (err) if (err)
return err; return err;
break; break;
...@@ -238,7 +240,8 @@ int ip_cmsg_send(struct net *net, struct msghdr *msg, struct ipcm_cookie *ipc) ...@@ -238,7 +240,8 @@ int ip_cmsg_send(struct net *net, struct msghdr *msg, struct ipcm_cookie *ipc)
struct ip_ra_chain *ip_ra_chain; struct ip_ra_chain *ip_ra_chain;
DEFINE_RWLOCK(ip_ra_lock); DEFINE_RWLOCK(ip_ra_lock);
int ip_ra_control(struct sock *sk, unsigned char on, void (*destructor)(struct sock *)) int ip_ra_control(struct sock *sk, unsigned char on,
void (*destructor)(struct sock *))
{ {
struct ip_ra_chain *ra, *new_ra, **rap; struct ip_ra_chain *ra, *new_ra, **rap;
...@@ -248,7 +251,7 @@ int ip_ra_control(struct sock *sk, unsigned char on, void (*destructor)(struct s ...@@ -248,7 +251,7 @@ int ip_ra_control(struct sock *sk, unsigned char on, void (*destructor)(struct s
new_ra = on ? kmalloc(sizeof(*new_ra), GFP_KERNEL) : NULL; new_ra = on ? kmalloc(sizeof(*new_ra), GFP_KERNEL) : NULL;
write_lock_bh(&ip_ra_lock); write_lock_bh(&ip_ra_lock);
for (rap = &ip_ra_chain; (ra=*rap) != NULL; rap = &ra->next) { for (rap = &ip_ra_chain; (ra = *rap) != NULL; rap = &ra->next) {
if (ra->sk == sk) { if (ra->sk == sk) {
if (on) { if (on) {
write_unlock_bh(&ip_ra_lock); write_unlock_bh(&ip_ra_lock);
...@@ -416,7 +419,8 @@ int ip_recv_error(struct sock *sk, struct msghdr *msg, int len) ...@@ -416,7 +419,8 @@ int ip_recv_error(struct sock *sk, struct msghdr *msg, int len)
/* Reset and regenerate socket error */ /* Reset and regenerate socket error */
spin_lock_bh(&sk->sk_error_queue.lock); spin_lock_bh(&sk->sk_error_queue.lock);
sk->sk_err = 0; sk->sk_err = 0;
if ((skb2 = skb_peek(&sk->sk_error_queue)) != NULL) { skb2 = skb_peek(&sk->sk_error_queue);
if (skb2 != NULL) {
sk->sk_err = SKB_EXT_ERR(skb2)->ee.ee_errno; sk->sk_err = SKB_EXT_ERR(skb2)->ee.ee_errno;
spin_unlock_bh(&sk->sk_error_queue.lock); spin_unlock_bh(&sk->sk_error_queue.lock);
sk->sk_error_report(sk); sk->sk_error_report(sk);
...@@ -431,8 +435,8 @@ out: ...@@ -431,8 +435,8 @@ out:
/* /*
* Socket option code for IP. This is the end of the line after any TCP,UDP etc options on * Socket option code for IP. This is the end of the line after any
* an IP socket. * TCP,UDP etc options on an IP socket.
*/ */
static int do_ip_setsockopt(struct sock *sk, int level, static int do_ip_setsockopt(struct sock *sk, int level,
...@@ -474,7 +478,7 @@ static int do_ip_setsockopt(struct sock *sk, int level, ...@@ -474,7 +478,7 @@ static int do_ip_setsockopt(struct sock *sk, int level,
switch (optname) { switch (optname) {
case IP_OPTIONS: case IP_OPTIONS:
{ {
struct ip_options * opt = NULL; struct ip_options *opt = NULL;
if (optlen > 40 || optlen < 0) if (optlen > 40 || optlen < 0)
goto e_inval; goto e_inval;
err = ip_options_get_from_user(sock_net(sk), &opt, err = ip_options_get_from_user(sock_net(sk), &opt,
...@@ -556,9 +560,9 @@ static int do_ip_setsockopt(struct sock *sk, int level, ...@@ -556,9 +560,9 @@ static int do_ip_setsockopt(struct sock *sk, int level,
} }
break; break;
case IP_TTL: case IP_TTL:
if (optlen<1) if (optlen < 1)
goto e_inval; goto e_inval;
if (val != -1 && (val < 1 || val>255)) if (val != -1 && (val < 0 || val > 255))
goto e_inval; goto e_inval;
inet->uc_ttl = val; inet->uc_ttl = val;
break; break;
...@@ -570,7 +574,7 @@ static int do_ip_setsockopt(struct sock *sk, int level, ...@@ -570,7 +574,7 @@ static int do_ip_setsockopt(struct sock *sk, int level,
inet->hdrincl = val ? 1 : 0; inet->hdrincl = val ? 1 : 0;
break; break;
case IP_MTU_DISCOVER: case IP_MTU_DISCOVER:
if (val<0 || val>3) if (val < 0 || val > 3)
goto e_inval; goto e_inval;
inet->pmtudisc = val; inet->pmtudisc = val;
break; break;
...@@ -582,7 +586,7 @@ static int do_ip_setsockopt(struct sock *sk, int level, ...@@ -582,7 +586,7 @@ static int do_ip_setsockopt(struct sock *sk, int level,
case IP_MULTICAST_TTL: case IP_MULTICAST_TTL:
if (sk->sk_type == SOCK_STREAM) if (sk->sk_type == SOCK_STREAM)
goto e_inval; goto e_inval;
if (optlen<1) if (optlen < 1)
goto e_inval; goto e_inval;
if (val == -1) if (val == -1)
val = 1; val = 1;
...@@ -591,7 +595,7 @@ static int do_ip_setsockopt(struct sock *sk, int level, ...@@ -591,7 +595,7 @@ static int do_ip_setsockopt(struct sock *sk, int level,
inet->mc_ttl = val; inet->mc_ttl = val;
break; break;
case IP_MULTICAST_LOOP: case IP_MULTICAST_LOOP:
if (optlen<1) if (optlen < 1)
goto e_inval; goto e_inval;
inet->mc_loop = !!val; inet->mc_loop = !!val;
break; break;
...@@ -613,7 +617,8 @@ static int do_ip_setsockopt(struct sock *sk, int level, ...@@ -613,7 +617,8 @@ static int do_ip_setsockopt(struct sock *sk, int level,
} else { } else {
memset(&mreq, 0, sizeof(mreq)); memset(&mreq, 0, sizeof(mreq));
if (optlen >= sizeof(struct in_addr) && if (optlen >= sizeof(struct in_addr) &&
copy_from_user(&mreq.imr_address, optval, sizeof(struct in_addr))) copy_from_user(&mreq.imr_address, optval,
sizeof(struct in_addr)))
break; break;
} }
...@@ -677,7 +682,6 @@ static int do_ip_setsockopt(struct sock *sk, int level, ...@@ -677,7 +682,6 @@ static int do_ip_setsockopt(struct sock *sk, int level,
} }
case IP_MSFILTER: case IP_MSFILTER:
{ {
extern int sysctl_igmp_max_msf;
struct ip_msfilter *msf; struct ip_msfilter *msf;
if (optlen < IP_MSFILTER_SIZE(0)) if (optlen < IP_MSFILTER_SIZE(0))
...@@ -831,7 +835,6 @@ static int do_ip_setsockopt(struct sock *sk, int level, ...@@ -831,7 +835,6 @@ static int do_ip_setsockopt(struct sock *sk, int level,
} }
case MCAST_MSFILTER: case MCAST_MSFILTER:
{ {
extern int sysctl_igmp_max_msf;
struct sockaddr_in *psin; struct sockaddr_in *psin;
struct ip_msfilter *msf = NULL; struct ip_msfilter *msf = NULL;
struct group_filter *gsf = NULL; struct group_filter *gsf = NULL;
...@@ -849,9 +852,9 @@ static int do_ip_setsockopt(struct sock *sk, int level, ...@@ -849,9 +852,9 @@ static int do_ip_setsockopt(struct sock *sk, int level,
break; break;
} }
err = -EFAULT; err = -EFAULT;
if (copy_from_user(gsf, optval, optlen)) { if (copy_from_user(gsf, optval, optlen))
goto mc_msf_out; goto mc_msf_out;
}
/* numsrc >= (4G-140)/128 overflow in 32 bits */ /* numsrc >= (4G-140)/128 overflow in 32 bits */
if (gsf->gf_numsrc >= 0x1ffffff || if (gsf->gf_numsrc >= 0x1ffffff ||
gsf->gf_numsrc > sysctl_igmp_max_msf) { gsf->gf_numsrc > sysctl_igmp_max_msf) {
...@@ -879,7 +882,7 @@ static int do_ip_setsockopt(struct sock *sk, int level, ...@@ -879,7 +882,7 @@ static int do_ip_setsockopt(struct sock *sk, int level,
msf->imsf_fmode = gsf->gf_fmode; msf->imsf_fmode = gsf->gf_fmode;
msf->imsf_numsrc = gsf->gf_numsrc; msf->imsf_numsrc = gsf->gf_numsrc;
err = -EADDRNOTAVAIL; err = -EADDRNOTAVAIL;
for (i=0; i<gsf->gf_numsrc; ++i) { for (i = 0; i < gsf->gf_numsrc; ++i) {
psin = (struct sockaddr_in *)&gsf->gf_slist[i]; psin = (struct sockaddr_in *)&gsf->gf_slist[i];
if (psin->sin_family != AF_INET) if (psin->sin_family != AF_INET)
...@@ -890,7 +893,7 @@ static int do_ip_setsockopt(struct sock *sk, int level, ...@@ -890,7 +893,7 @@ static int do_ip_setsockopt(struct sock *sk, int level,
gsf = NULL; gsf = NULL;
err = ip_mc_msfilter(sk, msf, ifindex); err = ip_mc_msfilter(sk, msf, ifindex);
mc_msf_out: mc_msf_out:
kfree(msf); kfree(msf);
kfree(gsf); kfree(gsf);
break; break;
...@@ -900,7 +903,7 @@ static int do_ip_setsockopt(struct sock *sk, int level, ...@@ -900,7 +903,7 @@ static int do_ip_setsockopt(struct sock *sk, int level,
break; break;
case IP_FREEBIND: case IP_FREEBIND:
if (optlen<1) if (optlen < 1)
goto e_inval; goto e_inval;
inet->freebind = !!val; inet->freebind = !!val;
break; break;
...@@ -957,6 +960,7 @@ int ip_setsockopt(struct sock *sk, int level, ...@@ -957,6 +960,7 @@ int ip_setsockopt(struct sock *sk, int level,
#endif #endif
return err; return err;
} }
EXPORT_SYMBOL(ip_setsockopt);
#ifdef CONFIG_COMPAT #ifdef CONFIG_COMPAT
int compat_ip_setsockopt(struct sock *sk, int level, int optname, int compat_ip_setsockopt(struct sock *sk, int level, int optname,
...@@ -986,13 +990,12 @@ int compat_ip_setsockopt(struct sock *sk, int level, int optname, ...@@ -986,13 +990,12 @@ int compat_ip_setsockopt(struct sock *sk, int level, int optname,
#endif #endif
return err; return err;
} }
EXPORT_SYMBOL(compat_ip_setsockopt); EXPORT_SYMBOL(compat_ip_setsockopt);
#endif #endif
/* /*
* Get the options. Note for future reference. The GET of IP options gets the * Get the options. Note for future reference. The GET of IP options gets
* _received_ ones. The set sets the _sent_ ones. * the _received_ ones. The set sets the _sent_ ones.
*/ */
static int do_ip_getsockopt(struct sock *sk, int level, int optname, static int do_ip_getsockopt(struct sock *sk, int level, int optname,
...@@ -1143,7 +1146,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname, ...@@ -1143,7 +1146,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
return -EFAULT; return -EFAULT;
} }
err = ip_mc_gsfget(sk, &gsf, err = ip_mc_gsfget(sk, &gsf,
(struct group_filter __user *)optval, optlen); (struct group_filter __user *)optval,
optlen);
release_sock(sk); release_sock(sk);
return err; return err;
} }
...@@ -1187,7 +1191,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname, ...@@ -1187,7 +1191,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
} }
release_sock(sk); release_sock(sk);
if (len < sizeof(int) && len > 0 && val>=0 && val<=255) { if (len < sizeof(int) && len > 0 && val >= 0 && val <= 255) {
unsigned char ucval = (unsigned char)val; unsigned char ucval = (unsigned char)val;
len = 1; len = 1;
if (put_user(len, optlen)) if (put_user(len, optlen))
...@@ -1230,6 +1234,7 @@ int ip_getsockopt(struct sock *sk, int level, ...@@ -1230,6 +1234,7 @@ int ip_getsockopt(struct sock *sk, int level,
#endif #endif
return err; return err;
} }
EXPORT_SYMBOL(ip_getsockopt);
#ifdef CONFIG_COMPAT #ifdef CONFIG_COMPAT
int compat_ip_getsockopt(struct sock *sk, int level, int optname, int compat_ip_getsockopt(struct sock *sk, int level, int optname,
...@@ -1262,11 +1267,5 @@ int compat_ip_getsockopt(struct sock *sk, int level, int optname, ...@@ -1262,11 +1267,5 @@ int compat_ip_getsockopt(struct sock *sk, int level, int optname,
#endif #endif
return err; return err;
} }
EXPORT_SYMBOL(compat_ip_getsockopt); EXPORT_SYMBOL(compat_ip_getsockopt);
#endif #endif
EXPORT_SYMBOL(ip_cmsg_recv);
EXPORT_SYMBOL(ip_getsockopt);
EXPORT_SYMBOL(ip_setsockopt);
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment