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

WAN driver update 4/5:

Clean up WAN device protocol structure accesses to be type-safe,
and not have to store the data length of structures.
parent fd0812f6
......@@ -247,21 +247,16 @@ static void cisco_close(hdlc_device *hdlc)
int hdlc_cisco_ioctl(hdlc_device *hdlc, struct ifreq *ifr)
{
cisco_proto *cisco_s = &ifr->ifr_settings->ifs_hdlc.cisco;
const size_t size = sizeof(cisco_proto);
struct net_device *dev = hdlc_to_dev(hdlc);
int result;
switch (ifr->ifr_settings.type) {
switch (ifr->ifr_settings->type) {
case IF_GET_PROTO:
ifr->ifr_settings.type = IF_PROTO_CISCO;
if (ifr->ifr_settings.data_length == 0)
return 0; /* return protocol only */
if (ifr->ifr_settings.data_length < size)
return -ENOMEM; /* buffer too small */
if (copy_to_user(ifr->ifr_settings.data,
&hdlc->state.cisco.settings, size))
ifr->ifr_settings->type = IF_PROTO_CISCO;
if (copy_to_user(cisco_s, &hdlc->state.cisco.settings, size))
return -EFAULT;
ifr->ifr_settings.data_length = size;
return 0;
case IF_PROTO_CISCO:
......@@ -271,11 +266,7 @@ int hdlc_cisco_ioctl(hdlc_device *hdlc, struct ifreq *ifr)
if(dev->flags & IFF_UP)
return -EBUSY;
if (ifr->ifr_settings.data_length != size)
return -ENOMEM; /* incorrect data length */
if (copy_from_user(&hdlc->state.cisco.settings,
ifr->ifr_settings.data, size))
if (copy_from_user(&hdlc->state.cisco.settings, cisco_s, size))
return -EFAULT;
/* FIXME - put sanity checks here */
......
......@@ -776,22 +776,17 @@ static void fr_destroy(hdlc_device *hdlc)
int hdlc_fr_ioctl(hdlc_device *hdlc, struct ifreq *ifr)
{
fr_proto *fr_s = &ifr->ifr_settings->ifs_hdlc.fr;
const size_t size = sizeof(fr_proto);
struct net_device *dev = hdlc_to_dev(hdlc);
fr_proto_pvc pvc;
int result;
switch (ifr->ifr_settings.type) {
switch (ifr->ifr_settings->type) {
case IF_GET_PROTO:
ifr->ifr_settings.type = IF_PROTO_FR;
if (ifr->ifr_settings.data_length == 0)
return 0; /* return protocol only */
if (ifr->ifr_settings.data_length < size)
return -ENOMEM; /* buffer too small */
if (copy_to_user(ifr->ifr_settings.data,
&hdlc->state.fr.settings, size))
ifr->ifr_settings->type = IF_PROTO_FR;
if (copy_to_user(fr_s, &hdlc->state.fr.settings, size))
return -EFAULT;
ifr->ifr_settings.data_length = size;
return 0;
case IF_PROTO_FR:
......@@ -801,11 +796,7 @@ int hdlc_fr_ioctl(hdlc_device *hdlc, struct ifreq *ifr)
if(dev->flags & IFF_UP)
return -EBUSY;
if (ifr->ifr_settings.data_length != size)
return -ENOMEM; /* incorrect data length */
if (copy_from_user(&hdlc->state.fr.settings,
ifr->ifr_settings.data, size))
if (copy_from_user(&hdlc->state.fr.settings, fr_s, size))
return -EFAULT;
/* FIXME - put sanity checks here */
......@@ -839,12 +830,12 @@ int hdlc_fr_ioctl(hdlc_device *hdlc, struct ifreq *ifr)
if(!capable(CAP_NET_ADMIN))
return -EPERM;
if (copy_from_user(&pvc, ifr->ifr_settings.data,
if (copy_from_user(&pvc, &ifr->ifr_settings->ifs_hdlc.fr_pvc,
sizeof(fr_proto_pvc)))
return -EFAULT;
return fr_pvc(hdlc, pvc.dlci,
ifr->ifr_settings.type == IF_PROTO_FR_ADD_PVC);
ifr->ifr_settings->type == IF_PROTO_FR_ADD_PVC);
}
return -EINVAL;
......
......@@ -75,13 +75,13 @@ int hdlc_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
if (cmd != SIOCWANDEV)
return -EINVAL;
switch(ifr->ifr_settings.type) {
switch(ifr->ifr_settings->type) {
case IF_PROTO_HDLC:
case IF_PROTO_PPP:
case IF_PROTO_CISCO:
case IF_PROTO_FR:
case IF_PROTO_X25:
proto = ifr->ifr_settings.type;
proto = ifr->ifr_settings->type;
break;
default:
......
......@@ -82,10 +82,9 @@ int hdlc_ppp_ioctl(hdlc_device *hdlc, struct ifreq *ifr)
struct net_device *dev = hdlc_to_dev(hdlc);
int result;
switch (ifr->ifr_settings.type) {
switch (ifr->ifr_settings->type) {
case IF_GET_PROTO:
ifr->ifr_settings.type = IF_PROTO_PPP;
ifr->ifr_settings.data_length = 0;
ifr->ifr_settings->type = IF_PROTO_PPP;
return 0; /* return protocol only, no settable parameters */
case IF_PROTO_PPP:
......@@ -95,8 +94,7 @@ int hdlc_ppp_ioctl(hdlc_device *hdlc, struct ifreq *ifr)
if(dev->flags & IFF_UP)
return -EBUSY;
if (ifr->ifr_settings.data_length != 0)
return -EINVAL; /* no settable parameters */
/* no settable parameters */
hdlc_detach(hdlc);
......
......@@ -37,21 +37,15 @@ static void raw_rx(struct sk_buff *skb)
int hdlc_raw_ioctl(hdlc_device *hdlc, struct ifreq *ifr)
{
const size_t size = sizeof(hdlc_proto);
raw_hdlc_proto *raw_s = &ifr->ifr_settings->ifs_hdlc.raw_hdlc;
const size_t size = sizeof(raw_hdlc_proto);
struct net_device *dev = hdlc_to_dev(hdlc);
int result;
switch (ifr->ifr_settings.type) {
switch (ifr->ifr_settings->type) {
case IF_GET_PROTO:
ifr->ifr_settings.type = IF_PROTO_HDLC;
if (ifr->ifr_settings.data_length == 0)
return 0; /* return protocol only */
if (ifr->ifr_settings.data_length < size)
return -ENOMEM; /* buffer too small */
if (copy_to_user(ifr->ifr_settings.data,
&hdlc->state.raw_hdlc.settings, size))
if (copy_to_user(raw_s, &hdlc->state.raw_hdlc.settings, size))
return -EFAULT;
ifr->ifr_settings.data_length = size;
return 0;
case IF_PROTO_HDLC:
......@@ -61,13 +55,10 @@ int hdlc_raw_ioctl(hdlc_device *hdlc, struct ifreq *ifr)
if(dev->flags & IFF_UP)
return -EBUSY;
if (ifr->ifr_settings.data_length != size)
return -ENOMEM; /* incorrect data length */
if (copy_from_user(&hdlc->state.raw_hdlc.settings,
ifr->ifr_settings.data, size))
if (copy_from_user(&hdlc->state.raw_hdlc.settings, raw_s, size))
return -EFAULT;
/* FIXME - put sanity checks here */
hdlc_detach(hdlc);
......
......@@ -184,10 +184,9 @@ int hdlc_x25_ioctl(hdlc_device *hdlc, struct ifreq *ifr)
struct net_device *dev = hdlc_to_dev(hdlc);
int result;
switch (ifr->ifr_settings.type) {
switch (ifr->ifr_settings->type) {
case IF_GET_PROTO:
ifr->ifr_settings.type = IF_PROTO_X25;
ifr->ifr_settings.data_length = 0;
ifr->ifr_settings->type = IF_PROTO_X25;
return 0; /* return protocol only, no settable parameters */
case IF_PROTO_X25:
......@@ -197,9 +196,6 @@ int hdlc_x25_ioctl(hdlc_device *hdlc, struct ifreq *ifr)
if(dev->flags & IFF_UP)
return -EBUSY;
if (ifr->ifr_settings.data_length != 0)
return -EINVAL; /* no settable parameters */
hdlc_detach(hdlc);
result=hdlc->attach(hdlc, ENCODING_NRZ,PARITY_CRC16_PR1_CCITT);
......
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