aboutsummaryrefslogtreecommitdiffstats
path: root/package/base-files/files/rom/note
diff options
context:
space:
mode:
authorHauke Mehrtens <hauke@hauke-m.de>2021-02-16 23:30:28 +0100
committerHauke Mehrtens <hauke@hauke-m.de>2021-02-16 23:30:28 +0100
commitd5ae5658730a82312a20e68220f92f611b11d094 (patch)
tree472c7beeec5c6a49009128df5186f75c303a6c87 /package/base-files/files/rom/note
parentc4a6851c7276084137d91a91ab598e5109452961 (diff)
downloadupstream-19.07.7.tar.gz
upstream-19.07.7.tar.bz2
upstream-19.07.7.zip
OpenWrt v19.07.7: adjust config defaultsv19.07.7
Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
Diffstat (limited to 'package/base-files/files/rom/note')
0 files changed, 0 insertions, 0 deletions
f='#n127'>127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296
/*
 * Copyright (C) 2004, 2005 Mike Wray <mike.wray@hp.com>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by the 
 * Free Software Foundation; either version 2 of the License, or (at your
 * option) any later version.
 * 
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
 * for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free software Foundation, Inc.,
 * 59 Temple Place, suite 330, Boston, MA 02111-1307 USA
 *
 */
#include <linux/config.h>
#include <linux/module.h>
#include <linux/types.h>
#include <linux/sched.h>
#include <linux/kernel.h>

#include <linux/skbuff.h>
#include <linux/netdevice.h>
#include <linux/in.h>
#include <linux/tcp.h>
#include <linux/udp.h>

#include <net/ip.h>
#include <net/protocol.h>

#include <linux/if_arp.h>
#include <linux/in6.h>
#include <linux/inetdevice.h>
#include <linux/arcdevice.h>
#include <linux/if_bridge.h>

#include <etherip.h>
#include <vnet.h>
#include <varp.h>
#include <vif.h>
#include <vnet_dev.h>
#include <random.h>

#define MODULE_NAME "VNET"
#define DEBUG 1
#undef DEBUG
#include "debug.h"

#if !defined(CONFIG_BRIDGE) && !defined(CONFIG_BRIDGE_MODULE)
#warning Should configure Ethernet Bridging in kernel Network Options
#endif

#ifndef CONFIG_BRIDGE_NETFILTER
#warning Should configure CONFIG_BRIDGE_NETFILTER in kernel
#endif

static void vnet_dev_destructor(struct net_device *dev){
    Vnet *vnet = dev->priv;
    if(vnet){
        if(vnet->dev == dev){
            vnet->dev = NULL;
        }
        dev->priv = NULL;
        Vnet_decref(vnet);
    }
    free_netdev(dev);
}

static struct net_device_stats *vnet_dev_get_stats(struct net_device *dev){
    static struct net_device_stats stats = {};
    Vnet *vnet = dev->priv;
    return (vnet ? &vnet->stats : &stats);
}

static int vnet_dev_change_mtu(struct net_device *dev, int mtu){
    int err = 0;
    Vnet *vnet = dev->priv;
    if (mtu < 68 || mtu > (vnet ? vnet->mtu : 1500)){
        err = -EINVAL;
        goto exit;
    }
    dev->mtu = mtu;
  exit:
    return err;
}

/** Remove the net device for a vnet.
 * Safe to call if the vnet or its dev are null.
 *
 * @param vnet vnet
 */
void vnet_dev_remove(Vnet *vnet){
    if(vnet && vnet->dev){
        iprintf("> Removing vnet device %s\n", vnet->dev->name);
        unregister_netdev(vnet->dev);
    }
}

static int vnet_dev_open(struct net_device *dev){
    int err = 0;

    netif_start_queue(dev);
    return err;
}

static int vnet_dev_stop(struct net_device *dev){
    int err = 0;

    netif_stop_queue(dev);
    return err;
}

static int vnet_dev_hard_start_xmit(struct sk_buff *skb, struct net_device *dev){
    int err = 0;
    Vnet *vnet = dev->priv;
    int len = 0;

    if(!skb){
        wprintf("> skb NULL!\n");
        return -EINVAL;
    }
    if(!vnet){
        return -ENOTCONN;
    }
    if(vnet->recursion++) {
        extern void print_skb(const char *msg, int count, struct sk_buff *skb);
        char vnetbuf[VNET_ID_BUF];
        
        vnet->stats.collisions++;
	vnet->stats.tx_errors++;
        wprintf("> recursion! vnet=%s\n", VnetId_ntoa(&vnet->vnet, vnetbuf));
        print_skb("RECURSION", 0, skb);
        varp_print(iostdout);
	kfree_skb(skb);
        goto exit;
    }
    if(!skb->mac.raw){
        skb->mac.raw = skb->data;
    }        
    len = skb->len;
    // Must not use skb pointer after vnet_skb_send().
    err = vnet_skb_send(skb, &vnet->vnet);
    if(err < 0){
        vnet->stats.tx_errors++;
    } else {
        vnet->stats.tx_packets++;
        vnet->stats.tx_bytes += len;
    }
  exit:
    vnet->recursion--;
    return 0;
}

void vnet_dev_set_multicast_list(struct net_device *dev){
}

#if 0
static int vnet_dev_do_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd){
    int err = 0;
    
    return err;
}

void vnet_dev_tx_timeout(struct net_device *dev){
    //dev->trans_start = jiffies;
    //netif_wake_queue(dev);
}

static int (*eth_hard_header)(struct sk_buff *skb,
                              struct net_device *dev, unsigned short type,
                              void *daddr, void *saddr, unsigned len) = NULL;

static int vnet_dev_hard_header(struct sk_buff *skb,
                                struct net_device *dev, unsigned short type,
                                void *daddr, void *saddr, unsigned len){
    int err = 0;

    err = eth_hard_header(skb, dev, type, daddr, saddr, len);
    if(err) goto exit;
    skb->mac.raw = skb->data;
  exit:
    return err;
}
#endif

int vnet_device_mac(const char *device, unsigned char *mac){
    int err;
    struct net_device *dev;

    err = vnet_get_device(device, &dev);
    if(err) goto exit;
    memcpy(mac, dev->dev_addr, ETH_ALEN);
    dev_put(dev);
  exit:
    return err;
}

void vnet_dev_mac(unsigned char *mac){
    mac[0] = 0xAA;
    mac[1] = 0xFF;
    get_random_bytes(mac + 2, 4);
}

/** Initial setup of the device for a vnet.
 */
static void vnet_dev_init(struct net_device *dev){
    ether_setup(dev);

#if 0
    if(!eth_hard_header){
        eth_hard_header = dev->hard_header;
    }
    dev->hard_header          = vnet_dev_hard_header;
    //dev->do_ioctl             = vnet_dev_do_ioctl;
    //dev->tx_timeout           = vnet_dev_tx_timeout;
    //dev->watchdog_timeo       = TX_TIMEOUT;
    
#endif

    dev->open                 = vnet_dev_open;
    dev->stop                 = vnet_dev_stop;
    dev->destructor           = vnet_dev_destructor;
    dev->hard_start_xmit      = vnet_dev_hard_start_xmit;
    dev->get_stats            = vnet_dev_get_stats;
    dev->change_mtu           = vnet_dev_change_mtu;
    dev->set_multicast_list   = vnet_dev_set_multicast_list;

    dev->flags |= IFF_DEBUG;
    dev->flags |= IFF_PROMISC;
    dev->flags |= IFF_ALLMULTI;

    vnet_dev_mac(dev->dev_addr);
}

/** Complete the setup of the device for a vnet.
 * Associate the device and the vnet and set mtu etc.
 */
static int vnet_dev_setup(Vnet *vnet, struct net_device *dev){
    int err;

    Vnet_incref(vnet);
    dev->priv = vnet;
    vnet->dev = dev;
    dev->hard_header_len += vnet->header_n;
    if(!etherip_in_udp){
        dev->mtu -= vnet->header_n;
    }
    vnet->mtu = dev->mtu;
    iprintf("> Adding vnet device %s\n", dev->name);
    err = register_netdev(dev);
    if(err){
        eprintf("> register_netdev(%s) = %d\n", dev->name, err);
        vnet_dev_destructor(dev);
    }
    return err;
}

static inline int roundupto(int n, int k){
    return k * ((n + k - 1) / k);