Exemplo n.º 1
0
static
struct net_device *ipmr_new_tunnel(struct net *net, struct vifctl *v)
{
	struct net_device  *dev;

	dev = __dev_get_by_name(net, "tunl0");

	if (dev) {
		const struct net_device_ops *ops = dev->netdev_ops;
		int err;
		struct ifreq ifr;
		struct ip_tunnel_parm p;
		struct in_device  *in_dev;

		memset(&p, 0, sizeof(p));
		p.iph.daddr = v->vifc_rmt_addr.s_addr;
		p.iph.saddr = v->vifc_lcl_addr.s_addr;
		p.iph.version = 4;
		p.iph.ihl = 5;
		p.iph.protocol = IPPROTO_IPIP;
		sprintf(p.name, "dvmrp%d", v->vifc_vifi);
		ifr.ifr_ifru.ifru_data = (__force void __user *)&p;

		if (ops->ndo_do_ioctl) {
			mm_segment_t oldfs = get_fs();

			set_fs(KERNEL_DS);
			err = ops->ndo_do_ioctl(dev, &ifr, SIOCADDTUNNEL);
			set_fs(oldfs);
		} else
			err = -EOPNOTSUPP;

		dev = NULL;

		if (err == 0 &&
		    (dev = __dev_get_by_name(net, p.name)) != NULL) {
			dev->flags |= IFF_MULTICAST;

			in_dev = __in_dev_get_rtnl(dev);
			if (in_dev == NULL)
				goto failure;

			ipv4_devconf_setall(in_dev);
			IPV4_DEVCONF(in_dev->cnf, RP_FILTER) = 0;

			if (dev_open(dev))
				goto failure;
			dev_hold(dev);
		}
	}
	return dev;

failure:
	/* allow the register to be completed before unregistering. */
	rtnl_unlock();
	rtnl_lock();

	unregister_netdevice(dev);
	return NULL;
}
static
struct net_device *ipmr_new_tunnel(struct vifctl *v)
{
	struct net_device  *dev;

	dev = __dev_get_by_name("tunl0");

	if (dev) {
		int err;
		struct ifreq ifr;
		mm_segment_t	oldfs;
		struct ip_tunnel_parm p;
		struct in_device  *in_dev;

		memset(&p, 0, sizeof(p));
		p.iph.daddr = v->vifc_rmt_addr.s_addr;
		p.iph.saddr = v->vifc_lcl_addr.s_addr;
		p.iph.version = 4;
		p.iph.ihl = 5;
		p.iph.protocol = IPPROTO_IPIP;
		sprintf(p.name, "dvmrp%d", v->vifc_vifi);
		ifr.ifr_ifru.ifru_data = (void*)&p;

		oldfs = get_fs(); set_fs(KERNEL_DS);
		err = dev->do_ioctl(dev, &ifr, SIOCADDTUNNEL);
		set_fs(oldfs);

		dev = NULL;

		if (err == 0 && (dev = __dev_get_by_name(p.name)) != NULL) {
			dev->flags |= IFF_MULTICAST;

			in_dev = __in_dev_get_rtnl(dev);
			if (in_dev == NULL && (in_dev = inetdev_init(dev)) == NULL)
				goto failure;
			in_dev->cnf.rp_filter = 0;

			if (dev_open(dev))
				goto failure;
		}
	}
	return dev;

failure:
	/* allow the register to be completed before unregistering. */
	rtnl_unlock();
	rtnl_lock();

	unregister_netdevice(dev);
	return NULL;
}
Exemplo n.º 3
0
static struct ip_tunnel * ipip_tunnel_locate(struct ip_tunnel_parm *parms, int create)
{
	u32 remote = parms->iph.daddr;
	u32 local = parms->iph.saddr;
	struct ip_tunnel *t, **tp, *nt;
	struct net_device *dev;
	unsigned h = 0;
	int prio = 0;
	char name[IFNAMSIZ];

	if (remote) {
		prio |= 2;
		h ^= HASH(remote);
	}
	if (local) {
		prio |= 1;
		h ^= HASH(local);
	}
	for (tp = &tunnels[prio][h]; (t = *tp) != NULL; tp = &t->next) {
		if (local == t->parms.iph.saddr && remote == t->parms.iph.daddr)
			return t;
	}
	if (!create)
		return NULL;

	if (parms->name[0])
		strlcpy(name, parms->name, IFNAMSIZ);
	else {
		int i;
		for (i=1; i<100; i++) {
			sprintf(name, "tunl%d", i);
			if (__dev_get_by_name(name) == NULL)
				break;
		}
		if (i==100)
			goto failed;
	}

	dev = alloc_netdev(sizeof(*t), name, ipip_tunnel_setup);
	if (dev == NULL)
		return NULL;

	nt = dev->priv;
	SET_MODULE_OWNER(dev);
	dev->init = ipip_tunnel_init;
	nt->parms = *parms;

	if (register_netdevice(dev) < 0) {
		free_netdev(dev);
		goto failed;
	}

	dev_hold(dev);
	ipip_tunnel_link(nt);
	/* Do not decrement MOD_USE_COUNT here. */
	return nt;

failed:
	return NULL;
}
Exemplo n.º 4
0
static int eql_s_slave_cfg(struct net_device *dev, slave_config_t *scp)
{
	slave_t *slave;
	equalizer_t *eql;
	struct net_device *slave_dev;
	slave_config_t sc;

	if (copy_from_user (&sc, scp, sizeof (slave_config_t)))
		return -EFAULT;

#ifdef EQL_DEBUG
	if (eql_debug >= 20)
		printk ("%s: set config for slave `%s'\n", dev->name, sc.slave_name);
#endif
  

	eql = (equalizer_t *) dev->priv;
	slave_dev = __dev_get_by_name (sc.slave_name);

	if ( eql_is_slave (slave_dev) )
	{
		slave = eql_find_slave_dev (eql->queue, slave_dev);
		if (slave != 0)
		{
			slave->priority = sc.priority;
			slave->priority_bps = sc.priority;
			slave->priority_Bps = sc.priority / 8;
			return 0;
		}
	}
	return -EINVAL;
}
Exemplo n.º 5
0
static int eql_emancipate(struct net_device *dev, slaving_request_t *srqp)
{
	struct net_device *master_dev;
	struct net_device *slave_dev;
	slaving_request_t srq;

	if (copy_from_user(&srq, srqp, sizeof (slaving_request_t)))
		return -EFAULT;

#ifdef EQL_DEBUG
	if (eql_debug >= 20)
		printk ("%s: emancipate `%s`\n", dev->name, srq.slave_name);
#endif
	master_dev = dev;		/* for "clarity" */
	slave_dev  = __dev_get_by_name (srq.slave_name);

	if ( eql_is_slave (slave_dev) )	/* really is a slave */
	{
		equalizer_t *eql = (equalizer_t *) master_dev->priv;
		slave_dev->flags = slave_dev->flags & ~IFF_SLAVE;
		eql_remove_slave_dev (eql->queue, slave_dev);
		return 0;
	}
	return -EINVAL;
}
Exemplo n.º 6
0
int br_del_bridge(char *name)
{
	struct net_device *dev;
	struct net_bridge *br;

	dev = __dev_get_by_name(name);
	if (!dev)
		return -ENXIO;

	if (dev->hard_start_xmit != br_dev_xmit)
		return -EPERM;

	if (dev->flags & IFF_UP)
		return -EBUSY;

	br = dev->priv;
	BUG_ON(&br->dev != dev);

	del_ifs(br);

	unregister_netdevice(dev);
	kfree(br);
	br_dec_use_count();

	return 0;
}
Exemplo n.º 7
0
static void xen_network_done_notify(void)
{
	static struct net_device *eth0_dev = NULL;
	if (unlikely(eth0_dev == NULL))
		eth0_dev = __dev_get_by_name("eth0");
	netif_rx_schedule(eth0_dev);
}
Exemplo n.º 8
0
int __init ip_list_init(void)
{
    struct net_device *dev;
    struct in_device *in_dev;

    dev = __dev_get_by_name(&init_net, ifname);
    if (dev == NULL)
    {
        printk(KERN_ERR "dev_get_by_name failed.\n");
        goto out;
    }

    in_dev = __in_dev_get_rcu(dev);
    if (!in_dev)
        goto out;
    
    for_ifa(in_dev)
    {
        __be32 addr = ifa->ifa_local;
        unsigned char *p = (unsigned char *)&addr;
    
        printk(KERN_INFO "%d.%d.%d.%d\n", *p, *(p+1), *(p+2), *(p+3));
    } endfor_ifa(in_dev);

    
    return 0;
out:
    return -ENODEV;
}
Exemplo n.º 9
0
static int eql_enslave(struct net_device *dev, slaving_request_t *srqp)
{
	struct net_device *master_dev;
	struct net_device *slave_dev;
	slaving_request_t srq;

	if (copy_from_user(&srq, srqp, sizeof (slaving_request_t)))
	  {
#ifdef EQL_DEBUG
	if (eql_debug >= 20)
		printk ("EQL enslave: error detected by copy_from_user\n");
#endif  
		return -EFAULT;
	  }

#ifdef EQL_DEBUG
	if (eql_debug >= 20)
		printk ("%s: enslave '%s' %ld bps\n", dev->name, 
			srq.slave_name, srq.priority);
#endif  
	master_dev = dev;		/* for "clarity" */
	slave_dev  = __dev_get_by_name (srq.slave_name);

	if (master_dev != 0 && slave_dev != 0)
	{
		if ((master_dev->flags & IFF_UP) == IFF_UP)
                {
			/*slave is not a master & not already a slave:*/
			if (! eql_is_master (slave_dev)  &&
			    ! eql_is_slave (slave_dev) )
			{
				slave_t *s = eql_new_slave ();
				equalizer_t *eql = 
					(equalizer_t *) master_dev->priv;
				if (!s)
					return -ENOMEM;
				s->dev = slave_dev;
				s->priority = srq.priority;
				s->priority_bps = srq.priority;
				s->priority_Bps = srq.priority / 8;
				slave_dev->flags |= IFF_SLAVE;
				eql_insert_slave (eql->queue, s);
				return 0;
			}
#ifdef EQL_DEBUG
			else if (eql_debug >= 20)
				printk ("EQL enslave: slave is master or slave is already slave\n");
#endif  
		}
#ifdef EQL_DEBUG
		else if (eql_debug >= 20)
			printk ("EQL enslave: master device not up!\n");
#endif  
	}
#ifdef EQL_DEBUG
	else if (eql_debug >= 20)
		printk ("EQL enslave: master or slave are NULL");
#endif  
	return -EINVAL;
}
Exemplo n.º 10
0
static void ipmr_del_tunnel(struct net_device *dev, struct vifctl *v)
{
	struct net *net = dev_net(dev);

	dev_close(dev);

	dev = __dev_get_by_name(net, "tunl0");
	if (dev) {
		const struct net_device_ops *ops = dev->netdev_ops;
		struct ifreq ifr;
		struct ip_tunnel_parm p;

		memset(&p, 0, sizeof(p));
		p.iph.daddr = v->vifc_rmt_addr.s_addr;
		p.iph.saddr = v->vifc_lcl_addr.s_addr;
		p.iph.version = 4;
		p.iph.ihl = 5;
		p.iph.protocol = IPPROTO_IPIP;
		sprintf(p.name, "dvmrp%d", v->vifc_vifi);
		ifr.ifr_ifru.ifru_data = (__force void __user *)&p;

		if (ops->ndo_do_ioctl) {
			mm_segment_t oldfs = get_fs();

			set_fs(KERNEL_DS);
			ops->ndo_do_ioctl(dev, &ifr, SIOCDELTUNNEL);
			set_fs(oldfs);
		}
	}
}
Exemplo n.º 11
0
static int bind_to_device(struct socket *sock, char *ifname)
{
	struct net *net;
	struct net_device *dev;
	__be32 addr;
	struct sockaddr_in sin;
	int err;
	
	net = sock_net(sock->sk);
	dev = __dev_get_by_name(net, ifname);
	if (!dev){
		printk("No such device named %s\n", ifname);
		return -ENODEV;
	}
	
	addr = inet_select_addr(dev, 0, RT_SCOPE_UNIVERSE);
	sin.sin_family = AF_INET;
	sin.sin_addr.s_addr = addr;
	sin.sin_port = 0;
	err = sock->ops->bind(sock, (struct sockaddr *)&sin, sizeof(sin));
	if (err < 0){
		printk("sock bind err, err=%d\n", err);
		return err;
	}
	return 0;
}
Exemplo n.º 12
0
int register_cl2llc_client(llcptr lp, const char *device, void (*event)(llcptr), u8 *rmac, u8 ssap, u8 dsap)
{
	char eye_init[] = "LLC\0";

	memset(lp, 0, sizeof(*lp));
	lp->dev = __dev_get_by_name(device);
	if(lp->dev == NULL)
		return -ENODEV;
	memcpy(lp->eye, eye_init, sizeof(lp->eye));
	lp->rw = 1;
	lp->k = 127;
	lp->n1 = 1490;
	lp->n2 = 10;
	lp->timer_interval[P_TIMER] = HZ;    /* 1 sec */
	lp->timer_interval[REJ_TIMER] = HZ/8;
	lp->timer_interval[ACK_TIMER] = HZ/8;
	lp->timer_interval[BUSY_TIMER] = HZ*2;
	lp->local_sap = ssap;
	lp->llc_event = event;
	memcpy(lp->remote_mac, rmac, sizeof(lp->remote_mac));
	lp->state = 0;
	lp->llc_mode = MODE_ADM;
	lp->remote_sap = dsap;
	skb_queue_head_init(&lp->atq);
	skb_queue_head_init(&lp->rtq);
	MOD_INC_USE_COUNT;
	return 0;
}
Exemplo n.º 13
0
/*
 * Main IOCTl dispatcher. Called from the main networking code
 * (dev_ioctl() in net/core/dev.c).
 * Check the type of IOCTL and call the appropriate wrapper...
 */
int wireless_process_ioctl(struct ifreq *ifr, unsigned int cmd)
{
	struct net_device *dev;
	iw_handler	handler;

	/* Permissions are already checked in dev_ioctl() before calling us.
	 * The copy_to/from_user() of ifr is also dealt with in there */

	/* Make sure the device exist */
	if ((dev = __dev_get_by_name(ifr->ifr_name)) == NULL)
		return -ENODEV;

	/* A bunch of special cases, then the generic case...
	 * Note that 'cmd' is already filtered in dev_ioctl() with
	 * (cmd >= SIOCIWFIRST && cmd <= SIOCIWLAST) */
	switch(cmd) 
	{
		case SIOCGIWSTATS:
			/* Get Wireless Stats */
			return dev_iwstats(dev, ifr);

		case SIOCGIWPRIV:
			/* Check if we have some wireless handlers defined */
			if(dev->wireless_handlers != NULL) {
				/* We export to user space the definition of
				 * the private handler ourselves */
				return ioctl_export_private(dev, ifr);
			}
			// ## Fall-through for old API ##
		default:
			/* Generic IOCTL */
			/* Basic check */
			if (!netif_device_present(dev))
				return -ENODEV;
			/* New driver API : try to find the handler */
			handler = get_handler(dev, cmd);
			if(handler != NULL) {
				/* Standard and private are not the same */
				if(cmd < SIOCIWFIRSTPRIV)
					return ioctl_standard_call(dev,
								   ifr,
								   cmd,
								   handler);
				else
					return ioctl_private_call(dev,
								  ifr,
								  cmd,
								  handler);
			}
			/* Old driver API : call driver ioctl handler */
			if (dev->do_ioctl) {
				return dev->do_ioctl(dev, ifr, cmd);
			}
			return -EOPNOTSUPP;
	}
	/* Not reached */
	return -EINVAL;
}
Exemplo n.º 14
0
static int dumb_neigh_dev_xmit(struct net *net, struct sk_buff *skb)
{
    struct net_device *dev;
    struct dst_entry *dst = (struct dst_entry*)skb->_skb_refdst;

    dev = __dev_get_by_name(net, skb->dev->name);
    skb->dev = dst->dev;
    skb->ip_summed = CHECKSUM_NONE;
    mpls_re_tx(skb,dev);
    return 0;
}
Exemplo n.º 15
0
struct ip_tunnel * ipip6_tunnel_locate(struct ip_tunnel_parm *parms, int create)
{
	u32 remote = parms->iph.daddr;
	u32 local = parms->iph.saddr;
	struct ip_tunnel *t, **tp, *nt;
	struct net_device *dev;

	for (tp = __ipip6_bucket(parms); (t = *tp) != NULL; tp = &t->next) {
		if (local == t->parms.iph.saddr && remote == t->parms.iph.daddr)
			return t;
	}
	if (!create)
		return NULL;

	MOD_INC_USE_COUNT;
	dev = kmalloc(sizeof(*dev) + sizeof(*t), GFP_KERNEL);
	if (dev == NULL) {
		MOD_DEC_USE_COUNT;
		return NULL;
	}
	memset(dev, 0, sizeof(*dev) + sizeof(*t));
	dev->priv = (void*)(dev+1);
	nt = (struct ip_tunnel*)dev->priv;
	nt->dev = dev;
	dev->init = ipip6_tunnel_init;
	dev->features |= NETIF_F_DYNALLOC;
	memcpy(&nt->parms, parms, sizeof(*parms));
	nt->parms.name[IFNAMSIZ-1] = '\0';
	strcpy(dev->name, nt->parms.name);
	if (dev->name[0] == 0) {
		int i;
		for (i=1; i<100; i++) {
			sprintf(dev->name, "sit%d", i);
			if (__dev_get_by_name(dev->name) == NULL)
				break;
		}
		if (i==100)
			goto failed;
		memcpy(nt->parms.name, dev->name, IFNAMSIZ);
	}
	if (register_netdevice(dev) < 0)
		goto failed;

	dev_hold(dev);
	ipip6_tunnel_link(nt);
	/* Do not decrement MOD_USE_COUNT here. */
	return nt;

failed:
	kfree(dev);
	MOD_DEC_USE_COUNT;
	return NULL;
}
Exemplo n.º 16
0
/*
 *	Set destination address.
 *	Special case for SIT interfaces where we create a new "virtual"
 *	device.
 */
int addrconf_set_dstaddr(void *arg)
{
	struct in6_ifreq ireq;
	struct net_device *dev;
	int err = -EINVAL;

	rtnl_lock();

	err = -EFAULT;
	if (copy_from_user(&ireq, arg, sizeof(struct in6_ifreq)))
		goto err_exit;

	dev = __dev_get_by_index(ireq.ifr6_ifindex);

	err = -ENODEV;
	if (dev == NULL)
		goto err_exit;

	if (dev->type == ARPHRD_SIT) {
		struct ifreq ifr;
		mm_segment_t	oldfs;
		struct ip_tunnel_parm p;

		err = -EADDRNOTAVAIL;
		if (!(ipv6_addr_type(&ireq.ifr6_addr) & IPV6_ADDR_COMPATv4))
			goto err_exit;

		memset(&p, 0, sizeof(p));
		p.iph.daddr = ireq.ifr6_addr.s6_addr32[3];
		p.iph.saddr = 0;
		p.iph.version = 4;
		p.iph.ihl = 5;
		p.iph.protocol = IPPROTO_IPV6;
		p.iph.ttl = 64;
		ifr.ifr_ifru.ifru_data = (void*)&p;

		oldfs = get_fs(); set_fs(KERNEL_DS);
		err = dev->do_ioctl(dev, &ifr, SIOCADDTUNNEL);
		set_fs(oldfs);

		if (err == 0) {
			err = -ENOBUFS;
			if ((dev = __dev_get_by_name(p.name)) == NULL)
				goto err_exit;
			err = dev_open(dev);
		}
	}

err_exit:
	rtnl_unlock();
	return err;
}
Exemplo n.º 17
0
static struct ip_tunnel * ipip6_tunnel_locate(struct ip_tunnel_parm *parms, int create)
{
	__be32 remote = parms->iph.daddr;
	__be32 local = parms->iph.saddr;
	struct ip_tunnel *t, **tp, *nt;
	struct net_device *dev;
	char name[IFNAMSIZ];

	for (tp = __ipip6_bucket(parms); (t = *tp) != NULL; tp = &t->next) {
		if (local == t->parms.iph.saddr && remote == t->parms.iph.daddr)
			return t;
	}
	if (!create)
		goto failed;

	if (parms->name[0])
		strlcpy(name, parms->name, IFNAMSIZ);
	else {
		int i;
		for (i=1; i<100; i++) {
			sprintf(name, "sit%d", i);
			if (__dev_get_by_name(name) == NULL)
				break;
		}
		if (i==100)
			goto failed;
	}

	dev = alloc_netdev(sizeof(*t), name, ipip6_tunnel_setup);
	if (dev == NULL)
		return NULL;

	nt = netdev_priv(dev);
	dev->init = ipip6_tunnel_init;
	nt->parms = *parms;

	if (register_netdevice(dev) < 0) {
		free_netdev(dev);
		goto failed;
	}

	dev_hold(dev);

	ipip6_tunnel_link(nt);
	return nt;

failed:
	return NULL;
}
Exemplo n.º 18
0
/*
 *      Specifiy default interface for outgoing multicasts
 */
static int set_mcast_if(struct sock *sk, char *ifname)
{
	struct net_device *dev;

	if ((dev = __dev_get_by_name(ifname)) == NULL)
		return -ENODEV;

	if (sk->bound_dev_if && dev->ifindex != sk->bound_dev_if)
		return -EINVAL;

	lock_sock(sk);
	sk->protinfo.af_inet.mc_index = dev->ifindex;
	/*  sk->protinfo.af_inet.mc_addr  = 0; */
	release_sock(sk);

	return 0;
}
Exemplo n.º 19
0
/* --------------------------------------------------------------------------
 * The initialization function: it is used to assign fields in the structure
 * Initializes the operation table and also the slave device to transmit the data 
 */
void vni_init(struct net_device *dev)
{
    struct net_device *slave;
    struct vni_private *priv; 

    ether_setup(dev); /* assign some of the fields as "generic ethernet" */
    memset(netdev_priv(dev), 0, sizeof(struct vni_private));
    
    dev->netdev_ops = &vni_net_device_ops;

    /* Assign random MAC address */
    random_ether_addr(dev->dev_addr);

    /* Hardcode the transmitting module to USB2 */
    /* interface name */
    priv = netdev_priv(dev);
    slave = __dev_get_by_name(&init_net, "usb2");
    if (!slave)
    {
         printk(" Slave Interface Doesn't exists , Returning\n");
         return;
    }
    if (slave->type != ARPHRD_ETHER && slave->type != ARPHRD_LOOPBACK)
    {
         printk("This is not compatible interface");
         return;

    }

    /* The interface is good, get hold of it */
    priv->priv_device = slave;
    if (slave->header_ops)
           dev->header_ops = &vni_header_ops;
    else
           dev->header_ops = NULL;

    /* also, and clone its IP, MAC and other information */
    memcpy(dev->dev_addr,  slave->dev_addr,  ETH_ALEN);
    memcpy(dev->broadcast, slave->broadcast, sizeof(slave->broadcast));

    /* Assign default value (no checks here) */
    priv->priv_mode = VNI_PASS;

}
Exemplo n.º 20
0
Arquivo: pg3.c Projeto: 2mac/iputils
static struct net_device *pg_setup_inject(u32 *saddrp)
{
	int p1, p2;
	struct net_device *odev;
	u32 saddr;

	rtnl_lock();
	odev = __dev_get_by_name(pg_outdev);
	if (!odev) {
		sprintf(pg_result, "No such netdevice: \"%s\"", pg_outdev);
		goto out_unlock;
	}

	if (odev->type != ARPHRD_ETHER) {
		sprintf(pg_result, "Not ethernet device: \"%s\"", pg_outdev);
		goto out_unlock;
	}

	if (!netif_running(odev)) {
		sprintf(pg_result, "Device is down: \"%s\"", pg_outdev);
		goto out_unlock;
	}

	for(p1=6,p2=0; p1 < odev->addr_len+6;p1++)
		hh[p1]=odev->dev_addr[p2++];

	saddr = 0;
	if (odev->ip_ptr) {
		struct in_device *in_dev = odev->ip_ptr;

		if (in_dev->ifa_list)
			saddr = in_dev->ifa_list->ifa_address;
	}
	atomic_inc(&odev->refcnt);
	rtnl_unlock();

	*saddrp = saddr;
	return odev;

out_unlock:
	rtnl_unlock();
	return NULL;
}
Exemplo n.º 21
0
int __init init( void ) {
   int err = 0;
   struct priv *priv;
   char ifstr[ 40 ];
   sprintf( ifstr, "%s%s", ifname, "%d" );
#if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 17, 0))
   child = alloc_netdev( sizeof( struct priv ), ifstr, setup );
#else
   child = alloc_netdev( sizeof( struct priv ), ifstr, NET_NAME_UNKNOWN, setup );
#endif
   if( child == NULL ) {
      ERR( "%s: allocate error", THIS_MODULE->name ); return -ENOMEM;
   }
   priv = netdev_priv( child );
   priv->parent = __dev_get_by_name( &init_net, link ); // parent interface  
   if( !priv->parent ) {
      ERR( "%s: no such net: %s", THIS_MODULE->name, link );
      err = -ENODEV; goto err;
   }
   if( priv->parent->type != ARPHRD_ETHER && priv->parent->type != ARPHRD_LOOPBACK ) {
      ERR( "%s: illegal net type", THIS_MODULE->name );
      err = -EINVAL; goto err;
   }
   /* also, and clone its IP, MAC and other information */
   memcpy( child->dev_addr, priv->parent->dev_addr, ETH_ALEN );
   memcpy( child->broadcast, priv->parent->broadcast, ETH_ALEN );
   if( ( err = dev_alloc_name( child, child->name ) ) ) {
      ERR( "%s: allocate name, error %i", THIS_MODULE->name, err );
      err = -EIO; goto err;
   }
   register_netdev( child );
   rtnl_lock();
   netdev_rx_handler_register( priv->parent, &handle_frame, NULL );
   rtnl_unlock();
   LOG( "module %s loaded", THIS_MODULE->name );
   LOG( "%s: create link %s", THIS_MODULE->name, child->name );
   LOG( "%s: registered rx handler for %s", THIS_MODULE->name, priv->parent->name );
   return 0;
err:
   free_netdev( child );
   return err;
}
Exemplo n.º 22
0
Arquivo: br_if.c Projeto: nhanh0/hah
int br_add_bridge(char *name)
{
	struct net_bridge *br;

	if ((br = new_nb(name)) == NULL)
		return -ENOMEM;

	if (__dev_get_by_name(name) != NULL) {
		kfree(br);
		return -EEXIST;
	}

	br->next = bridge_list;
	bridge_list = br;

	br_inc_use_count();
	register_netdev(&br->dev);

	return 0;
}
Exemplo n.º 23
0
/*
 * Main IOCTl dispatcher.
 * Check the type of IOCTL and call the appropriate wrapper...
 */
static int wireless_process_ioctl(struct net *net, struct ifreq *ifr, unsigned int cmd)
{
	struct net_device *dev;
	iw_handler	handler;

	/* Permissions are already checked in dev_ioctl() before calling us.
	 * The copy_to/from_user() of ifr is also dealt with in there */

	/* Make sure the device exist */
	if ((dev = __dev_get_by_name(net, ifr->ifr_name)) == NULL)
		return -ENODEV;

	/* A bunch of special cases, then the generic case...
	 * Note that 'cmd' is already filtered in dev_ioctl() with
	 * (cmd >= SIOCIWFIRST && cmd <= SIOCIWLAST) */
	if (cmd == SIOCGIWSTATS)
		return ioctl_standard_call(dev, ifr, cmd,
					   &iw_handler_get_iwstats);

	if (cmd == SIOCGIWPRIV && dev->wireless_handlers)
		return ioctl_standard_call(dev, ifr, cmd,
					   &iw_handler_get_private);

	/* Basic check */
	if (!netif_device_present(dev))
		return -ENODEV;

	/* New driver API : try to find the handler */
	handler = get_handler(dev, cmd);
	if (handler) {
		/* Standard and private are not the same */
		if (cmd < SIOCIWFIRSTPRIV)
			return ioctl_standard_call(dev, ifr, cmd, handler);
		else
			return ioctl_private_call(dev, ifr, cmd, handler);
	}
	/* Old driver API : call driver ioctl handler */
	if (dev->do_ioctl)
		return dev->do_ioctl(dev, ifr, cmd);
	return -EOPNOTSUPP;
}
Exemplo n.º 24
0
// function to set/reset the device promisciuity
void set_prom(int val){
	if(val==1)
	printk("Setting promiscious mode on\n");
	else
	printk("Setting promiscious mode off\n");

	if ( (dev = __dev_get_by_name(DEVNAME)) == NULL ){
		printk("Error opening device eth0\n");
		return ;
	}
	
	dev->flags = (dev->flags & ~(IFF_PROMISC|IFF_ALLMULTI| \
			IFF_RUNNING))|(dev->gflags & \
			(IFF_PROMISC|IFF_ALLMULTI));
	
	if( netif_running(dev) && netif_carrier_ok(dev)) {
		dev->flags |= IFF_RUNNING;
		dev->flags |= IFF_PROMISC;
	}	

	dev_set_promiscuity(dev,val);
}
Exemplo n.º 25
0
int get_hwaddr(char *ifname, __u8 *hwaddr)
{
	if(strstr(ifname,"bridge"))
	{
		hwaddr[0] = 0x00;
		hwaddr[1] = 0x19;
		hwaddr[2] = 0xc7;
		hwaddr[3] = 0x00;
		hwaddr[4] = 0x00;
		hwaddr[5] = 0x00;		
		return 0;
	}
    struct net_device *dev = __dev_get_by_name(&init_net,ifname);
    if (dev == NULL)
    {
        printk("get interface %s fail \r\n",ifname);
        return -1;
    }
	memcpy(hwaddr,dev->dev_addr,6);

	return 0;
}
Exemplo n.º 26
0
static int
ip6_tnl_create(struct ip6_tnl_parm *p, struct ip6_tnl **pt)
{
	struct net_device *dev;
	struct ip6_tnl *t;
	char name[IFNAMSIZ];
	int err;

	if (p->name[0]) {
		strlcpy(name, p->name, IFNAMSIZ);
	} else {
		int i;
		for (i = 1; i < IP6_TNL_MAX; i++) {
			sprintf(name, "ip6tnl%d", i);
			if (__dev_get_by_name(name) == NULL)
				break;
		}
		if (i == IP6_TNL_MAX) 
			return -ENOBUFS;
	}
	dev = alloc_netdev(sizeof (*t), name, ip6ip6_tnl_dev_setup);
	if (dev == NULL)
		return -ENOMEM;

	t = netdev_priv(dev);
	dev->init = ip6ip6_tnl_dev_init;
	t->parms = *p;

	if ((err = register_netdevice(dev)) < 0) {
		free_netdev(dev);
		return err;
	}
	dev_hold(dev);

	ip6ip6_tnl_link(t);
	*pt = t;
	return 0;
}
Exemplo n.º 27
0
/*
 *      Join a multicast group.
 *      the group is specified by a class D multicast address 224.0.0.0/8
 *      in the in_addr structure passed in as a parameter.
 */
static int
join_mcast_group(struct sock *sk, struct in_addr *addr, char *ifname)
{
	struct ip_mreqn mreq;
	struct net_device *dev;
	int ret;

	memset(&mreq, 0, sizeof(mreq));
	memcpy(&mreq.imr_multiaddr, addr, sizeof(struct in_addr));

	if ((dev = __dev_get_by_name(ifname)) == NULL)
		return -ENODEV;
	if (sk->bound_dev_if && dev->ifindex != sk->bound_dev_if)
		return -EINVAL;

	mreq.imr_ifindex = dev->ifindex;

	lock_sock(sk);
	ret = ip_mc_join_group(sk, &mreq);
	release_sock(sk);

	return ret;
}
Exemplo n.º 28
0
int ethtool_ioctl(struct ifreq *ifr){
	struct net_device *netdev=__dev_get_by_name(ifr->ifr_name);
	void *useraddr=(void *)ifr->ifr_data;
	uint32_t ethcmd;

	if(!capable(CAP_NET_ADMIN))
		return -EPERM;

	if(!netdev || !netif_device_present(netdev))
		return -ENODEV;
	if(copy_from_user(&ethcmd, useraddr, sizeof(ethcmd)))
		return -EFAULT;
	
	switch (ethcmd){
	case ETHTOOL_GSET:
		return ethtool_get_settings(netdev,useraddr);
	case ETHTOOL_SSET:
		return ethtool_set_settings(netdev,useraddr);
	default:
		return -EOPNOTSUPP;
	}
	return -EOPNOTSUPP;
}
static long modem_net_flowcontrol_device_ioctl(
			struct file *filp, unsigned int cmd, unsigned long arg)
{
	struct net *this_net;
	struct net_device *ndev;
	char dev_name[NET_FLOWCONTROL_DEV_NAME_LEN];
	u8 chan;

	if (copy_from_user(&chan, (void __user *)arg, sizeof(char)))
		return -EFAULT;

	if (chan > 15)
		return -ENODEV;

	snprintf(dev_name, NET_FLOWCONTROL_DEV_NAME_LEN, "rmnet%d", (int)chan);
	this_net = get_net_ns_by_pid(current->pid);
	ndev = __dev_get_by_name(this_net, dev_name);
	if (ndev == NULL) {
		pr_err("MIF: %s: device = %s not exist\n", __func__,
					dev_name);
		return -ENODEV;
	}

	switch (cmd) {
	case IOCTL_MODEM_NET_SUSPEND:
		netif_stop_queue(ndev);
		pr_info("MIF: NET SUSPEND(%s)\n", dev_name);
		break;
	case IOCTL_MODEM_NET_RESUME:
		netif_wake_queue(ndev);
		pr_info("MIF: NET RESUME(%s)\n", dev_name);
		break;
	default:
		return -EINVAL;
	}
	return 0;
}
Exemplo n.º 30
0
static int shaper_ioctl(struct net_device *dev,  struct ifreq *ifr, int cmd)
{
	struct shaperconf *ss= (struct shaperconf *)&ifr->ifr_ifru;
	struct shaper *sh=dev->priv;

	if(ss->ss_cmd == SHAPER_SET_DEV || ss->ss_cmd == SHAPER_SET_SPEED)
	{
		if(!capable(CAP_NET_ADMIN))
			return -EPERM;
	}

	switch(ss->ss_cmd)
	{
		case SHAPER_SET_DEV:
		{
			struct net_device *them=__dev_get_by_name(ss->ss_name);
			if(them==NULL)
				return -ENODEV;
			if(sh->dev)
				return -EBUSY;
			return shaper_attach(dev,dev->priv, them);
		}
		case SHAPER_GET_DEV:
			if(sh->dev==NULL)
				return -ENODEV;
			strcpy(ss->ss_name, sh->dev->name);
			return 0;
		case SHAPER_SET_SPEED:
			shaper_setspeed(sh,ss->ss_speed);
			return 0;
		case SHAPER_GET_SPEED:
			ss->ss_speed=sh->bitspersec;
			return 0;
		default:
			return -EINVAL;
	}
}