Commit 7d98230a authored by Jeff Dike's avatar Jeff Dike Committed by Linus Torvalds

uml: network and pcap cleanup

Some network device cleanup.

When setup_etheraddr found a globally valid MAC being assigned to an
interface, it went ahead and used it rather than assigning a random MAC like
the other cases do.  This isn't really an error like the others, but it seems
consistent to make it behave the same.

We were getting some duplicate kfree() in the error case in eth_configure
because platform_device_unregister frees buffers that the error cases
following tried to free again.

The pcap initialization routine wasn't doing the proper printk of its
information, causing a printk of the first part of that line to be
unterminated by a newline.

The pcap code had a bunch of style violations, which are now fixed.

pcap_setup wasn't returning false when it detected an unrecognized
option.

The printks in pcap_user all got UM_KERN_BLAH prepended to their
format strings.

pcap_remove now checks for a non-NULL pcap structure before it calls
pcap_close.
Signed-off-by: default avatarJeff Dike <jdike@linux.intel.com>
Acked-by: default avatarPaolo 'Blaisorblade' Giarrusso <blaisorblade@yahoo.it>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent a436ed9c
...@@ -316,12 +316,14 @@ static void setup_etheraddr(char *str, unsigned char *addr, char *name) ...@@ -316,12 +316,14 @@ static void setup_etheraddr(char *str, unsigned char *addr, char *name)
} }
if (!is_local_ether_addr(addr)) { if (!is_local_ether_addr(addr)) {
printk(KERN_WARNING printk(KERN_WARNING
"Warning: attempt to assign a globally valid ethernet address to a " "Warning: attempt to assign a globally valid ethernet "
"device\n"); "address to a device\n");
printk(KERN_WARNING "You should better enable the 2nd rightmost bit " printk(KERN_WARNING "You should better enable the 2nd "
"in the first byte of the MAC, i.e. " "rightmost bit in the first byte of the MAC,\n");
"%02x:%02x:%02x:%02x:%02x:%02x\n", printk(KERN_WARNING "i.e. %02x:%02x:%02x:%02x:%02x:%02x\n",
addr[0] | 0x02, addr[1], addr[2], addr[3], addr[4], addr[5]); addr[0] | 0x02, addr[1], addr[2], addr[3], addr[4],
addr[5]);
goto random;
} }
return; return;
...@@ -478,6 +480,7 @@ static void eth_configure(int n, void *init, char *mac, ...@@ -478,6 +480,7 @@ static void eth_configure(int n, void *init, char *mac,
(*transport->user->remove)(&lp->user); (*transport->user->remove)(&lp->user);
out_unregister: out_unregister:
platform_device_unregister(&device->pdev); platform_device_unregister(&device->pdev);
return; /* platform_device_unregister frees dev and device */
out_free_netdev: out_free_netdev:
free_netdev(dev); free_netdev(dev);
out_free_device: out_free_device:
......
...@@ -29,21 +29,25 @@ void pcap_init(struct net_device *dev, void *data) ...@@ -29,21 +29,25 @@ void pcap_init(struct net_device *dev, void *data)
ppri->promisc = init->promisc; ppri->promisc = init->promisc;
ppri->optimize = init->optimize; ppri->optimize = init->optimize;
ppri->filter = init->filter; ppri->filter = init->filter;
printk("pcap backend, host interface %s\n", ppri->host_if);
} }
static int pcap_read(int fd, struct sk_buff **skb, static int pcap_read(int fd, struct sk_buff **skb,
struct uml_net_private *lp) struct uml_net_private *lp)
{ {
*skb = ether_adjust_skb(*skb, ETH_HEADER_OTHER); *skb = ether_adjust_skb(*skb, ETH_HEADER_OTHER);
if(*skb == NULL) return(-ENOMEM); if(*skb == NULL)
return(pcap_user_read(fd, skb_mac_header(*skb), return -ENOMEM;
return pcap_user_read(fd, skb_mac_header(*skb),
(*skb)->dev->mtu + ETH_HEADER_OTHER, (*skb)->dev->mtu + ETH_HEADER_OTHER,
(struct pcap_data *) &lp->user)); (struct pcap_data *) &lp->user);
} }
static int pcap_write(int fd, struct sk_buff **skb, struct uml_net_private *lp) static int pcap_write(int fd, struct sk_buff **skb, struct uml_net_private *lp)
{ {
return(-EPERM); return -EPERM;
} }
static const struct net_kern_info pcap_kern_info = { static const struct net_kern_info pcap_kern_info = {
...@@ -65,12 +69,12 @@ int pcap_setup(char *str, char **mac_out, void *data) ...@@ -65,12 +69,12 @@ int pcap_setup(char *str, char **mac_out, void *data)
.optimize = 0, .optimize = 0,
.filter = NULL }); .filter = NULL });
remain = split_if_spec(str, &host_if, &init->filter, remain = split_if_spec(str, &host_if, &init->filter,
&options[0], &options[1], NULL); &options[0], &options[1], NULL);
if(remain != NULL){ if(remain != NULL){
printk(KERN_ERR "pcap_setup - Extra garbage on " printk(KERN_ERR "pcap_setup - Extra garbage on "
"specification : '%s'\n", remain); "specification : '%s'\n", remain);
return(0); return 0;
} }
if(host_if != NULL) if(host_if != NULL)
...@@ -87,10 +91,13 @@ int pcap_setup(char *str, char **mac_out, void *data) ...@@ -87,10 +91,13 @@ int pcap_setup(char *str, char **mac_out, void *data)
init->optimize = 1; init->optimize = 1;
else if(!strcmp(options[i], "nooptimize")) else if(!strcmp(options[i], "nooptimize"))
init->optimize = 0; init->optimize = 0;
else printk("pcap_setup : bad option - '%s'\n", options[i]); else {
printk("pcap_setup : bad option - '%s'\n", options[i]);
return 0;
}
} }
return(1); return 1;
} }
static struct transport pcap_transport = { static struct transport pcap_transport = {
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include "pcap_user.h" #include "pcap_user.h"
#include "user.h" #include "user.h"
#include "um_malloc.h" #include "um_malloc.h"
#include "kern_constants.h"
#define MAX_PACKET (ETH_MAX_PACKET + ETH_HEADER_OTHER) #define MAX_PACKET (ETH_MAX_PACKET + ETH_HEADER_OTHER)
...@@ -26,8 +27,8 @@ static int pcap_user_init(void *data, void *dev) ...@@ -26,8 +27,8 @@ static int pcap_user_init(void *data, void *dev)
p = pcap_open_live(pri->host_if, MAX_PACKET, pri->promisc, 0, errors); p = pcap_open_live(pri->host_if, MAX_PACKET, pri->promisc, 0, errors);
if(p == NULL){ if(p == NULL){
printk("pcap_user_init : pcap_open_live failed - '%s'\n", printk(UM_KERN_ERR "pcap_user_init : pcap_open_live failed - "
errors); "'%s'\n", errors);
return -EINVAL; return -EINVAL;
} }
...@@ -48,13 +49,13 @@ static int pcap_open(void *data) ...@@ -48,13 +49,13 @@ static int pcap_open(void *data)
if(pri->filter != NULL){ if(pri->filter != NULL){
err = dev_netmask(pri->dev, &netmask); err = dev_netmask(pri->dev, &netmask);
if(err < 0){ if(err < 0){
printk("pcap_open : dev_netmask failed\n"); printk(UM_KERN_ERR "pcap_open : dev_netmask failed\n");
return -EIO; return -EIO;
} }
pri->compiled = um_kmalloc(sizeof(struct bpf_program)); pri->compiled = um_kmalloc(sizeof(struct bpf_program));
if(pri->compiled == NULL){ if(pri->compiled == NULL){
printk("pcap_open : kmalloc failed\n"); printk(UM_KERN_ERR "pcap_open : kmalloc failed\n");
return -ENOMEM; return -ENOMEM;
} }
...@@ -62,15 +63,15 @@ static int pcap_open(void *data) ...@@ -62,15 +63,15 @@ static int pcap_open(void *data)
(struct bpf_program *) pri->compiled, (struct bpf_program *) pri->compiled,
pri->filter, pri->optimize, netmask); pri->filter, pri->optimize, netmask);
if(err < 0){ if(err < 0){
printk("pcap_open : pcap_compile failed - '%s'\n", printk(UM_KERN_ERR "pcap_open : pcap_compile failed - "
pcap_geterr(pri->pcap)); "'%s'\n", pcap_geterr(pri->pcap));
return -EIO; return -EIO;
} }
err = pcap_setfilter(pri->pcap, pri->compiled); err = pcap_setfilter(pri->pcap, pri->compiled);
if(err < 0){ if(err < 0){
printk("pcap_open : pcap_setfilter failed - '%s'\n", printk(UM_KERN_ERR "pcap_open : pcap_setfilter "
pcap_geterr(pri->pcap)); "failed - '%s'\n", pcap_geterr(pri->pcap));
return -EIO; return -EIO;
} }
} }
...@@ -85,7 +86,8 @@ static void pcap_remove(void *data) ...@@ -85,7 +86,8 @@ static void pcap_remove(void *data)
if(pri->compiled != NULL) if(pri->compiled != NULL)
pcap_freecode(pri->compiled); pcap_freecode(pri->compiled);
pcap_close(pri->pcap); if(pri->pcap != NULL)
pcap_close(pri->pcap);
} }
struct pcap_handler_data { struct pcap_handler_data {
...@@ -114,7 +116,8 @@ int pcap_user_read(int fd, void *buffer, int len, struct pcap_data *pri) ...@@ -114,7 +116,8 @@ int pcap_user_read(int fd, void *buffer, int len, struct pcap_data *pri)
n = pcap_dispatch(pri->pcap, 1, handler, (u_char *) &hdata); n = pcap_dispatch(pri->pcap, 1, handler, (u_char *) &hdata);
if(n < 0){ if(n < 0){
printk("pcap_dispatch failed - %s\n", pcap_geterr(pri->pcap)); printk(UM_KERN_ERR "pcap_dispatch failed - %s\n",
pcap_geterr(pri->pcap));
return -EIO; return -EIO;
} }
else if(n == 0) else if(n == 0)
......
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