Commit fd0812f6 authored by François Romieu's avatar François Romieu Committed by Jeff Garzik

WAN drivers update 3/5:

Clean up WAN driver ioctl handling to be more independent
of line settings structure changes.
parent 10e9aaa7
...@@ -179,9 +179,10 @@ static int c101_close(struct net_device *dev) ...@@ -179,9 +179,10 @@ static int c101_close(struct net_device *dev)
static int c101_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) static int c101_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
{ {
union line_settings *line = &ifr->ifr_settings->ifs_line;
const size_t size = sizeof(sync_serial_settings);
hdlc_device *hdlc = dev_to_hdlc(dev); hdlc_device *hdlc = dev_to_hdlc(dev);
port_t *port = hdlc_to_port(hdlc); port_t *port = hdlc_to_port(hdlc);
const size_t size = sizeof(sync_serial_settings);
#ifdef CONFIG_HDLC_DEBUG_RINGS #ifdef CONFIG_HDLC_DEBUG_RINGS
if (cmd == SIOCDEVPRIVATE) { if (cmd == SIOCDEVPRIVATE) {
...@@ -192,28 +193,18 @@ static int c101_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) ...@@ -192,28 +193,18 @@ static int c101_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
if (cmd != SIOCWANDEV) if (cmd != SIOCWANDEV)
return hdlc_ioctl(dev, ifr, cmd); return hdlc_ioctl(dev, ifr, cmd);
switch(ifr->ifr_settings.type) { switch(ifr->ifr_settings->type) {
case IF_GET_IFACE: case IF_GET_IFACE:
ifr->ifr_settings.type = IF_IFACE_SYNC_SERIAL; ifr->ifr_settings->type = IF_IFACE_SYNC_SERIAL;
if (ifr->ifr_settings.data_length == 0) if (copy_to_user(&line->sync, &port->settings, size))
return 0; /* return interface type only */
if (ifr->ifr_settings.data_length < size)
return -ENOMEM; /* buffer too small */
if (copy_to_user(ifr->ifr_settings.data,
&port->settings, size))
return -EFAULT; return -EFAULT;
ifr->ifr_settings.data_length = size;
return 0; return 0;
case IF_IFACE_SYNC_SERIAL: case IF_IFACE_SYNC_SERIAL:
if(!capable(CAP_NET_ADMIN)) if(!capable(CAP_NET_ADMIN))
return -EPERM; return -EPERM;
if (ifr->ifr_settings.data_length != size) if (copy_from_user(&port->settings, &line->sync, size))
return -ENOMEM; /* incorrect data length */
if (copy_from_user(&port->settings,
ifr->ifr_settings.data, size))
return -EFAULT; return -EFAULT;
/* FIXME - put sanity checks here */ /* FIXME - put sanity checks here */
return c101_set_iface(port); return c101_set_iface(port);
......
...@@ -1065,8 +1065,8 @@ static int dscc4_set_clock(struct net_device *dev, u32 *bps, u32 *state) ...@@ -1065,8 +1065,8 @@ static int dscc4_set_clock(struct net_device *dev, u32 *bps, u32 *state)
static int dscc4_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) static int dscc4_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
{ {
union line_settings *line = &ifr->ifr_settings->ifs_line;
struct dscc4_dev_priv *dpriv = dscc4_priv(dev); struct dscc4_dev_priv *dpriv = dscc4_priv(dev);
struct if_settings *if_s = &ifr->ifr_settings;
const size_t size = sizeof(dpriv->settings); const size_t size = sizeof(dpriv->settings);
int ret = 0; int ret = 0;
...@@ -1076,26 +1076,18 @@ static int dscc4_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) ...@@ -1076,26 +1076,18 @@ static int dscc4_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
if (cmd != SIOCWANDEV) if (cmd != SIOCWANDEV)
return -EOPNOTSUPP; return -EOPNOTSUPP;
switch(ifr->ifr_settings.type) { switch(ifr->ifr_settings->type) {
case IF_GET_IFACE: case IF_GET_IFACE:
if_s->type = IF_IFACE_SYNC_SERIAL; ifr->ifr_settings->type = IF_IFACE_SYNC_SERIAL;
if (if_s->data_length == 0) if (copy_to_user(&line->sync, &dpriv->settings, size))
return 0;
if (if_s->data_length < size)
return -ENOMEM;
if (copy_to_user(if_s->data, &dpriv->settings, size))
return -EFAULT; return -EFAULT;
if_s->data_length = size;
break; break;
case IF_IFACE_SYNC_SERIAL: case IF_IFACE_SYNC_SERIAL:
if(!capable(CAP_NET_ADMIN)) if(!capable(CAP_NET_ADMIN))
return -EPERM; return -EPERM;
if (if_s->data_length != size) if (copy_from_user(&dpriv->settings, &line->sync, size))
return -ENOMEM;
if (copy_from_user(&dpriv->settings, if_s->data, size))
return -EFAULT; return -EFAULT;
ret = dscc4_set_iface(dev); ret = dscc4_set_iface(dev);
break; break;
......
...@@ -1013,25 +1013,19 @@ static int ...@@ -1013,25 +1013,19 @@ static int
fst_set_iface ( struct fst_card_info *card, struct fst_port_info *port, fst_set_iface ( struct fst_card_info *card, struct fst_port_info *port,
struct ifreq *ifr ) struct ifreq *ifr )
{ {
union line_settings *line = &ifr->ifr_settings->ifs_line;
sync_serial_settings sync; sync_serial_settings sync;
int i; int i;
if ( ifr->ifr_settings.data_length != sizeof ( sync )) if ( copy_from_user ( &sync, &line->sync, sizeof ( sync )))
{
return -ENOMEM;
}
if ( copy_from_user ( &sync, ifr->ifr_settings.data, sizeof ( sync )))
{
return -EFAULT; return -EFAULT;
}
if ( sync.loopback ) if ( sync.loopback )
return -EINVAL; return -EINVAL;
i = port->index; i = port->index;
switch ( ifr->ifr_settings.type ) switch ( ifr->ifr_settings->type )
{ {
case IF_IFACE_V35: case IF_IFACE_V35:
FST_WRW ( card, portConfig[i].lineInterface, V35 ); FST_WRW ( card, portConfig[i].lineInterface, V35 );
...@@ -1076,6 +1070,7 @@ static int ...@@ -1076,6 +1070,7 @@ static int
fst_get_iface ( struct fst_card_info *card, struct fst_port_info *port, fst_get_iface ( struct fst_card_info *card, struct fst_port_info *port,
struct ifreq *ifr ) struct ifreq *ifr )
{ {
union line_settings *line = &ifr->ifr_settings->ifs_line;
sync_serial_settings sync; sync_serial_settings sync;
int i; int i;
...@@ -1086,25 +1081,16 @@ fst_get_iface ( struct fst_card_info *card, struct fst_port_info *port, ...@@ -1086,25 +1081,16 @@ fst_get_iface ( struct fst_card_info *card, struct fst_port_info *port,
switch ( port->hwif ) switch ( port->hwif )
{ {
case V35: case V35:
ifr->ifr_settings.type = IF_IFACE_V35; ifr->ifr_settings->type = IF_IFACE_V35;
break; break;
case V24: case V24:
ifr->ifr_settings.type = IF_IFACE_V24; ifr->ifr_settings->type = IF_IFACE_V24;
break; break;
case X21: case X21:
default: default:
ifr->ifr_settings.type = IF_IFACE_X21; ifr->ifr_settings->type = IF_IFACE_X21;
break; break;
} }
if ( ifr->ifr_settings.data_length == 0 )
{
return 0; /* only type requested */
}
if ( ifr->ifr_settings.data_length < sizeof ( sync ))
{
return -ENOMEM;
}
i = port->index; i = port->index;
sync.clock_rate = FST_RDL ( card, portConfig[i].lineSpeed ); sync.clock_rate = FST_RDL ( card, portConfig[i].lineSpeed );
...@@ -1112,12 +1098,9 @@ fst_get_iface ( struct fst_card_info *card, struct fst_port_info *port, ...@@ -1112,12 +1098,9 @@ fst_get_iface ( struct fst_card_info *card, struct fst_port_info *port,
sync.clock_type = FST_RDB ( card, portConfig[i].internalClock ); sync.clock_type = FST_RDB ( card, portConfig[i].internalClock );
sync.loopback = 0; sync.loopback = 0;
if ( copy_to_user ( ifr->ifr_settings.data, &sync, sizeof ( sync ))) if ( copy_to_user (&line->sync, &sync, sizeof ( sync )))
{
return -EFAULT; return -EFAULT;
}
ifr->ifr_settings.data_length = sizeof ( sync );
return 0; return 0;
} }
...@@ -1241,7 +1224,7 @@ fst_ioctl ( struct net_device *dev, struct ifreq *ifr, int cmd ) ...@@ -1241,7 +1224,7 @@ fst_ioctl ( struct net_device *dev, struct ifreq *ifr, int cmd )
return set_conf_from_info ( card, port, &info ); return set_conf_from_info ( card, port, &info );
case SIOCWANDEV: case SIOCWANDEV:
switch ( ifr->ifr_settings.type ) switch ( ifr->ifr_settings->type )
{ {
case IF_GET_IFACE: case IF_GET_IFACE:
return fst_get_iface ( card, port, ifr ); return fst_get_iface ( card, port, ifr );
......
...@@ -250,9 +250,10 @@ static int n2_close(struct net_device *dev) ...@@ -250,9 +250,10 @@ static int n2_close(struct net_device *dev)
static int n2_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) static int n2_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
{ {
union line_settings *line = &ifr->ifr_settings->ifs_line;
const size_t size = sizeof(sync_serial_settings);
hdlc_device *hdlc = dev_to_hdlc(dev); hdlc_device *hdlc = dev_to_hdlc(dev);
port_t *port = hdlc_to_port(hdlc); port_t *port = hdlc_to_port(hdlc);
const size_t size = sizeof(sync_serial_settings);
#ifdef CONFIG_HDLC_DEBUG_RINGS #ifdef CONFIG_HDLC_DEBUG_RINGS
if (cmd == SIOCDEVPRIVATE) { if (cmd == SIOCDEVPRIVATE) {
...@@ -263,28 +264,18 @@ static int n2_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) ...@@ -263,28 +264,18 @@ static int n2_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
if (cmd != SIOCWANDEV) if (cmd != SIOCWANDEV)
return hdlc_ioctl(dev, ifr, cmd); return hdlc_ioctl(dev, ifr, cmd);
switch(ifr->ifr_settings.type) { switch(ifr->ifr_settings->type) {
case IF_GET_IFACE: case IF_GET_IFACE:
ifr->ifr_settings.type = IF_IFACE_SYNC_SERIAL; ifr->ifr_settings->type = IF_IFACE_SYNC_SERIAL;
if (ifr->ifr_settings.data_length == 0) if (copy_to_user(&line->sync, &port->settings, size))
return 0; /* return interface type only */
if (ifr->ifr_settings.data_length < size)
return -ENOMEM; /* buffer too small */
if (copy_to_user(ifr->ifr_settings.data,
&port->settings, size))
return -EFAULT; return -EFAULT;
ifr->ifr_settings.data_length = size;
return 0; return 0;
case IF_IFACE_SYNC_SERIAL: case IF_IFACE_SYNC_SERIAL:
if(!capable(CAP_NET_ADMIN)) if(!capable(CAP_NET_ADMIN))
return -EPERM; return -EPERM;
if (ifr->ifr_settings.data_length != size) if (copy_from_user(&port->settings, &line->sync, size))
return -ENOMEM; /* incorrect data length */
if (copy_from_user(&port->settings,
ifr->ifr_settings.data, size))
return -EFAULT; return -EFAULT;
/* FIXME - put sanity checks here */ /* FIXME - put sanity checks here */
return n2_set_iface(port); return n2_set_iface(port);
......
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