2019-08-25 12:49:16 +03:00
// SPDX-License-Identifier: GPL-2.0
2005-04-17 02:20:36 +04:00
/*
2007-10-16 12:27:29 +04:00
* Copyright ( C ) 2002 - 2007 Jeff Dike ( jdike @ { addtoit , linux . intel } . com )
2005-04-17 02:20:36 +04:00
*/
2012-10-08 06:27:32 +04:00
# include <linux/init.h>
2007-10-16 12:27:29 +04:00
# include <linux/netdevice.h>
2012-10-08 06:27:32 +04:00
# include <net_kern.h>
2005-04-17 02:20:36 +04:00
# include "pcap_user.h"
struct pcap_init {
char * host_if ;
int promisc ;
int optimize ;
char * filter ;
} ;
void pcap_init ( struct net_device * dev , void * data )
{
struct uml_net_private * pri ;
struct pcap_data * ppri ;
struct pcap_init * init = data ;
2008-12-05 02:07:33 +03:00
pri = netdev_priv ( dev ) ;
2005-04-17 02:20:36 +04:00
ppri = ( struct pcap_data * ) pri - > user ;
ppri - > host_if = init - > host_if ;
ppri - > promisc = init - > promisc ;
ppri - > optimize = init - > optimize ;
ppri - > filter = init - > filter ;
2007-05-08 11:35:04 +04:00
printk ( " pcap backend, host interface %s \n " , ppri - > host_if ) ;
2005-04-17 02:20:36 +04:00
}
2007-10-16 12:27:31 +04:00
static int pcap_read ( int fd , struct sk_buff * skb , struct uml_net_private * lp )
2005-04-17 02:20:36 +04:00
{
2007-10-16 12:27:31 +04:00
return pcap_user_read ( fd , skb_mac_header ( skb ) ,
skb - > dev - > mtu + ETH_HEADER_OTHER ,
2007-05-08 11:35:04 +04:00
( struct pcap_data * ) & lp - > user ) ;
2005-04-17 02:20:36 +04:00
}
2007-10-16 12:27:31 +04:00
static int pcap_write ( int fd , struct sk_buff * skb , struct uml_net_private * lp )
2005-04-17 02:20:36 +04:00
{
2007-05-08 11:35:04 +04:00
return - EPERM ;
2005-04-17 02:20:36 +04:00
}
2006-09-27 12:50:33 +04:00
static const struct net_kern_info pcap_kern_info = {
2005-04-17 02:20:36 +04:00
. init = pcap_init ,
. protocol = eth_protocol ,
. read = pcap_read ,
. write = pcap_write ,
} ;
int pcap_setup ( char * str , char * * mac_out , void * data )
{
struct pcap_init * init = data ;
char * remain , * host_if = NULL , * options [ 2 ] = { NULL , NULL } ;
int i ;
* init = ( ( struct pcap_init )
{ . host_if = " eth0 " ,
. promisc = 1 ,
. optimize = 0 ,
. filter = NULL } ) ;
2007-05-08 11:35:04 +04:00
remain = split_if_spec ( str , & host_if , & init - > filter ,
2007-05-08 11:35:06 +04:00
& options [ 0 ] , & options [ 1 ] , mac_out , NULL ) ;
2007-10-16 12:27:29 +04:00
if ( remain ! = NULL ) {
2005-04-17 02:20:36 +04:00
printk ( KERN_ERR " pcap_setup - Extra garbage on "
" specification : '%s' \n " , remain ) ;
2007-05-08 11:35:04 +04:00
return 0 ;
2005-04-17 02:20:36 +04:00
}
2007-10-16 12:27:29 +04:00
if ( host_if ! = NULL )
2005-04-17 02:20:36 +04:00
init - > host_if = host_if ;
2007-10-16 12:27:29 +04:00
for ( i = 0 ; i < ARRAY_SIZE ( options ) ; i + + ) {
if ( options [ i ] = = NULL )
2005-04-17 02:20:36 +04:00
continue ;
2007-10-16 12:27:29 +04:00
if ( ! strcmp ( options [ i ] , " promisc " ) )
2005-04-17 02:20:36 +04:00
init - > promisc = 1 ;
2007-10-16 12:27:29 +04:00
else if ( ! strcmp ( options [ i ] , " nopromisc " ) )
2005-04-17 02:20:36 +04:00
init - > promisc = 0 ;
2007-10-16 12:27:29 +04:00
else if ( ! strcmp ( options [ i ] , " optimize " ) )
2005-04-17 02:20:36 +04:00
init - > optimize = 1 ;
2007-10-16 12:27:29 +04:00
else if ( ! strcmp ( options [ i ] , " nooptimize " ) )
2005-04-17 02:20:36 +04:00
init - > optimize = 0 ;
2007-05-08 11:35:04 +04:00
else {
2007-10-16 12:27:29 +04:00
printk ( KERN_ERR " pcap_setup : bad option - '%s' \n " ,
options [ i ] ) ;
2007-05-08 11:35:04 +04:00
return 0 ;
}
2005-04-17 02:20:36 +04:00
}
2007-05-08 11:35:04 +04:00
return 1 ;
2005-04-17 02:20:36 +04:00
}
static struct transport pcap_transport = {
. list = LIST_HEAD_INIT ( pcap_transport . list ) ,
. name = " pcap " ,
. setup = pcap_setup ,
. user = & pcap_user_info ,
. kern = & pcap_kern_info ,
. private_size = sizeof ( struct pcap_data ) ,
. setup_size = sizeof ( struct pcap_init ) ,
} ;
static int register_pcap ( void )
{
register_transport ( & pcap_transport ) ;
2006-03-31 14:30:10 +04:00
return 0 ;
2005-04-17 02:20:36 +04:00
}
2006-12-07 07:34:55 +03:00
late_initcall ( register_pcap ) ;