aboutsummaryrefslogtreecommitdiffstats
path: root/arch/um/drivers/pcap_user.c
diff options
context:
space:
mode:
Diffstat (limited to 'arch/um/drivers/pcap_user.c')
-rw-r--r--arch/um/drivers/pcap_user.c58
1 files changed, 30 insertions, 28 deletions
diff --git a/arch/um/drivers/pcap_user.c b/arch/um/drivers/pcap_user.c
index 1316456e2a28..e9809356c530 100644
--- a/arch/um/drivers/pcap_user.c
+++ b/arch/um/drivers/pcap_user.c
@@ -1,21 +1,17 @@
1/* 1/*
2 * Copyright (C) 2002 Jeff Dike <jdike@karaya.com> 2 * Copyright (C) 2002 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
3 * Licensed under the GPL. 3 * Licensed under the GPL.
4 */ 4 */
5 5
6#include <unistd.h>
7#include <stdlib.h>
8#include <string.h>
9#include <errno.h> 6#include <errno.h>
10#include <pcap.h> 7#include <pcap.h>
8#include <string.h>
11#include <asm/types.h> 9#include <asm/types.h>
12#include "net_user.h" 10#include "net_user.h"
13#include "pcap_user.h" 11#include "pcap_user.h"
14#include "user.h"
15#include "um_malloc.h"
16#include "kern_constants.h" 12#include "kern_constants.h"
17 13#include "um_malloc.h"
18#define MAX_PACKET (ETH_MAX_PACKET + ETH_HEADER_OTHER) 14#include "user.h"
19 15
20#define PCAP_FD(p) (*(int *)(p)) 16#define PCAP_FD(p) (*(int *)(p))
21 17
@@ -25,8 +21,9 @@ static int pcap_user_init(void *data, void *dev)
25 pcap_t *p; 21 pcap_t *p;
26 char errors[PCAP_ERRBUF_SIZE]; 22 char errors[PCAP_ERRBUF_SIZE];
27 23
28 p = pcap_open_live(pri->host_if, MAX_PACKET, pri->promisc, 0, errors); 24 p = pcap_open_live(pri->host_if, ETH_MAX_PACKET + ETH_HEADER_OTHER,
29 if(p == NULL){ 25 pri->promisc, 0, errors);
26 if (p == NULL) {
30 printk(UM_KERN_ERR "pcap_user_init : pcap_open_live failed - " 27 printk(UM_KERN_ERR "pcap_user_init : pcap_open_live failed - "
31 "'%s'\n", errors); 28 "'%s'\n", errors);
32 return -EINVAL; 29 return -EINVAL;
@@ -43,50 +40,55 @@ static int pcap_open(void *data)
43 __u32 netmask; 40 __u32 netmask;
44 int err; 41 int err;
45 42
46 if(pri->pcap == NULL) 43 if (pri->pcap == NULL)
47 return -ENODEV; 44 return -ENODEV;
48 45
49 if(pri->filter != NULL){ 46 if (pri->filter != NULL) {
50 err = dev_netmask(pri->dev, &netmask); 47 err = dev_netmask(pri->dev, &netmask);
51 if(err < 0){ 48 if (err < 0) {
52 printk(UM_KERN_ERR "pcap_open : dev_netmask failed\n"); 49 printk(UM_KERN_ERR "pcap_open : dev_netmask failed\n");
53 return -EIO; 50 return -EIO;
54 } 51 }
55 52
56 pri->compiled = kmalloc(sizeof(struct bpf_program), UM_GFP_KERNEL); 53 pri->compiled = kmalloc(sizeof(struct bpf_program),
57 if(pri->compiled == NULL){ 54 UM_GFP_KERNEL);
55 if (pri->compiled == NULL) {
58 printk(UM_KERN_ERR "pcap_open : kmalloc failed\n"); 56 printk(UM_KERN_ERR "pcap_open : kmalloc failed\n");
59 return -ENOMEM; 57 return -ENOMEM;
60 } 58 }
61 59
62 err = pcap_compile(pri->pcap, 60 err = pcap_compile(pri->pcap,
63 (struct bpf_program *) pri->compiled, 61 (struct bpf_program *) pri->compiled,
64 pri->filter, pri->optimize, netmask); 62 pri->filter, pri->optimize, netmask);
65 if(err < 0){ 63 if (err < 0) {
66 printk(UM_KERN_ERR "pcap_open : pcap_compile failed - " 64 printk(UM_KERN_ERR "pcap_open : pcap_compile failed - "
67 "'%s'\n", pcap_geterr(pri->pcap)); 65 "'%s'\n", pcap_geterr(pri->pcap));
68 return -EIO; 66 goto out;
69 } 67 }
70 68
71 err = pcap_setfilter(pri->pcap, pri->compiled); 69 err = pcap_setfilter(pri->pcap, pri->compiled);
72 if(err < 0){ 70 if (err < 0) {
73 printk(UM_KERN_ERR "pcap_open : pcap_setfilter " 71 printk(UM_KERN_ERR "pcap_open : pcap_setfilter "
74 "failed - '%s'\n", pcap_geterr(pri->pcap)); 72 "failed - '%s'\n", pcap_geterr(pri->pcap));
75 return -EIO; 73 goto out;
76 } 74 }
77 } 75 }
78 76
79 return PCAP_FD(pri->pcap); 77 return PCAP_FD(pri->pcap);
78
79 out:
80 kfree(pri->compiled);
81 return -EIO;
80} 82}
81 83
82static void pcap_remove(void *data) 84static void pcap_remove(void *data)
83{ 85{
84 struct pcap_data *pri = data; 86 struct pcap_data *pri = data;
85 87
86 if(pri->compiled != NULL) 88 if (pri->compiled != NULL)
87 pcap_freecode(pri->compiled); 89 pcap_freecode(pri->compiled);
88 90
89 if(pri->pcap != NULL) 91 if (pri->pcap != NULL)
90 pcap_close(pri->pcap); 92 pcap_close(pri->pcap);
91} 93}
92 94
@@ -95,7 +97,7 @@ struct pcap_handler_data {
95 int len; 97 int len;
96}; 98};
97 99
98static void handler(u_char *data, const struct pcap_pkthdr *header, 100static void handler(u_char *data, const struct pcap_pkthdr *header,
99 const u_char *packet) 101 const u_char *packet)
100{ 102{
101 int len; 103 int len;
@@ -115,12 +117,12 @@ int pcap_user_read(int fd, void *buffer, int len, struct pcap_data *pri)
115 int n; 117 int n;
116 118
117 n = pcap_dispatch(pri->pcap, 1, handler, (u_char *) &hdata); 119 n = pcap_dispatch(pri->pcap, 1, handler, (u_char *) &hdata);
118 if(n < 0){ 120 if (n < 0) {
119 printk(UM_KERN_ERR "pcap_dispatch failed - %s\n", 121 printk(UM_KERN_ERR "pcap_dispatch failed - %s\n",
120 pcap_geterr(pri->pcap)); 122 pcap_geterr(pri->pcap));
121 return -EIO; 123 return -EIO;
122 } 124 }
123 else if(n == 0) 125 else if (n == 0)
124 return 0; 126 return 0;
125 return hdata.len; 127 return hdata.len;
126} 128}
@@ -130,8 +132,8 @@ const struct net_user_info pcap_user_info = {
130 .open = pcap_open, 132 .open = pcap_open,
131 .close = NULL, 133 .close = NULL,
132 .remove = pcap_remove, 134 .remove = pcap_remove,
133 .set_mtu = NULL,
134 .add_address = NULL, 135 .add_address = NULL,
135 .delete_address = NULL, 136 .delete_address = NULL,
136 .max_packet = MAX_PACKET - ETH_HEADER_OTHER 137 .mtu = ETH_MAX_PACKET,
138 .max_packet = ETH_MAX_PACKET + ETH_HEADER_OTHER,
137}; 139};