net_kern.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864
  1. /*
  2. * Copyright (C) 2001 Lennert Buytenhek (buytenh@gnu.org) and
  3. * James Leu (jleu@mindspring.net).
  4. * Copyright (C) 2001 by various other people who didn't put their name here.
  5. * Licensed under the GPL.
  6. */
  7. #include "linux/kernel.h"
  8. #include "linux/netdevice.h"
  9. #include "linux/rtnetlink.h"
  10. #include "linux/skbuff.h"
  11. #include "linux/socket.h"
  12. #include "linux/spinlock.h"
  13. #include "linux/module.h"
  14. #include "linux/init.h"
  15. #include "linux/etherdevice.h"
  16. #include "linux/list.h"
  17. #include "linux/inetdevice.h"
  18. #include "linux/ctype.h"
  19. #include "linux/bootmem.h"
  20. #include "linux/ethtool.h"
  21. #include "linux/platform_device.h"
  22. #include "asm/uaccess.h"
  23. #include "user_util.h"
  24. #include "kern_util.h"
  25. #include "net_kern.h"
  26. #include "net_user.h"
  27. #include "mconsole_kern.h"
  28. #include "init.h"
  29. #include "irq_user.h"
  30. #include "irq_kern.h"
  31. static inline void set_ether_mac(struct net_device *dev, unsigned char *addr)
  32. {
  33. memcpy(dev->dev_addr, addr, ETH_ALEN);
  34. }
  35. #define DRIVER_NAME "uml-netdev"
  36. static DEFINE_SPINLOCK(opened_lock);
  37. static LIST_HEAD(opened);
  38. static int uml_net_rx(struct net_device *dev)
  39. {
  40. struct uml_net_private *lp = dev->priv;
  41. int pkt_len;
  42. struct sk_buff *skb;
  43. /* If we can't allocate memory, try again next round. */
  44. skb = dev_alloc_skb(dev->mtu);
  45. if (skb == NULL) {
  46. lp->stats.rx_dropped++;
  47. return 0;
  48. }
  49. skb->dev = dev;
  50. skb_put(skb, dev->mtu);
  51. skb->mac.raw = skb->data;
  52. pkt_len = (*lp->read)(lp->fd, &skb, lp);
  53. if (pkt_len > 0) {
  54. skb_trim(skb, pkt_len);
  55. skb->protocol = (*lp->protocol)(skb);
  56. netif_rx(skb);
  57. lp->stats.rx_bytes += skb->len;
  58. lp->stats.rx_packets++;
  59. return pkt_len;
  60. }
  61. kfree_skb(skb);
  62. return pkt_len;
  63. }
  64. static void uml_dev_close(void* dev)
  65. {
  66. dev_close( (struct net_device *) dev);
  67. }
  68. irqreturn_t uml_net_interrupt(int irq, void *dev_id)
  69. {
  70. struct net_device *dev = dev_id;
  71. struct uml_net_private *lp = dev->priv;
  72. int err;
  73. if(!netif_running(dev))
  74. return(IRQ_NONE);
  75. spin_lock(&lp->lock);
  76. while((err = uml_net_rx(dev)) > 0) ;
  77. if(err < 0) {
  78. DECLARE_WORK(close_work, uml_dev_close, dev);
  79. printk(KERN_ERR
  80. "Device '%s' read returned %d, shutting it down\n",
  81. dev->name, err);
  82. /* dev_close can't be called in interrupt context, and takes
  83. * again lp->lock.
  84. * And dev_close() can be safely called multiple times on the
  85. * same device, since it tests for (dev->flags & IFF_UP). So
  86. * there's no harm in delaying the device shutdown. */
  87. schedule_work(&close_work);
  88. #error this is not permitted - close_work will go out of scope
  89. goto out;
  90. }
  91. reactivate_fd(lp->fd, UM_ETH_IRQ);
  92. out:
  93. spin_unlock(&lp->lock);
  94. return(IRQ_HANDLED);
  95. }
  96. static int uml_net_open(struct net_device *dev)
  97. {
  98. struct uml_net_private *lp = dev->priv;
  99. int err;
  100. if(lp->fd >= 0){
  101. err = -ENXIO;
  102. goto out;
  103. }
  104. lp->fd = (*lp->open)(&lp->user);
  105. if(lp->fd < 0){
  106. err = lp->fd;
  107. goto out;
  108. }
  109. err = um_request_irq(dev->irq, lp->fd, IRQ_READ, uml_net_interrupt,
  110. IRQF_DISABLED | IRQF_SHARED, dev->name, dev);
  111. if(err != 0){
  112. printk(KERN_ERR "uml_net_open: failed to get irq(%d)\n", err);
  113. err = -ENETUNREACH;
  114. goto out_close;
  115. }
  116. lp->tl.data = (unsigned long) &lp->user;
  117. netif_start_queue(dev);
  118. /* clear buffer - it can happen that the host side of the interface
  119. * is full when we get here. In this case, new data is never queued,
  120. * SIGIOs never arrive, and the net never works.
  121. */
  122. while((err = uml_net_rx(dev)) > 0) ;
  123. spin_lock(&opened_lock);
  124. list_add(&lp->list, &opened);
  125. spin_unlock(&opened_lock);
  126. return 0;
  127. out_close:
  128. if(lp->close != NULL) (*lp->close)(lp->fd, &lp->user);
  129. lp->fd = -1;
  130. out:
  131. return err;
  132. }
  133. static int uml_net_close(struct net_device *dev)
  134. {
  135. struct uml_net_private *lp = dev->priv;
  136. netif_stop_queue(dev);
  137. free_irq(dev->irq, dev);
  138. if(lp->close != NULL)
  139. (*lp->close)(lp->fd, &lp->user);
  140. lp->fd = -1;
  141. spin_lock(&opened_lock);
  142. list_del(&lp->list);
  143. spin_unlock(&opened_lock);
  144. return 0;
  145. }
  146. static int uml_net_start_xmit(struct sk_buff *skb, struct net_device *dev)
  147. {
  148. struct uml_net_private *lp = dev->priv;
  149. unsigned long flags;
  150. int len;
  151. netif_stop_queue(dev);
  152. spin_lock_irqsave(&lp->lock, flags);
  153. len = (*lp->write)(lp->fd, &skb, lp);
  154. if(len == skb->len) {
  155. lp->stats.tx_packets++;
  156. lp->stats.tx_bytes += skb->len;
  157. dev->trans_start = jiffies;
  158. netif_start_queue(dev);
  159. /* this is normally done in the interrupt when tx finishes */
  160. netif_wake_queue(dev);
  161. }
  162. else if(len == 0){
  163. netif_start_queue(dev);
  164. lp->stats.tx_dropped++;
  165. }
  166. else {
  167. netif_start_queue(dev);
  168. printk(KERN_ERR "uml_net_start_xmit: failed(%d)\n", len);
  169. }
  170. spin_unlock_irqrestore(&lp->lock, flags);
  171. dev_kfree_skb(skb);
  172. return 0;
  173. }
  174. static struct net_device_stats *uml_net_get_stats(struct net_device *dev)
  175. {
  176. struct uml_net_private *lp = dev->priv;
  177. return &lp->stats;
  178. }
  179. static void uml_net_set_multicast_list(struct net_device *dev)
  180. {
  181. if (dev->flags & IFF_PROMISC) return;
  182. else if (dev->mc_count) dev->flags |= IFF_ALLMULTI;
  183. else dev->flags &= ~IFF_ALLMULTI;
  184. }
  185. static void uml_net_tx_timeout(struct net_device *dev)
  186. {
  187. dev->trans_start = jiffies;
  188. netif_wake_queue(dev);
  189. }
  190. static int uml_net_set_mac(struct net_device *dev, void *addr)
  191. {
  192. struct uml_net_private *lp = dev->priv;
  193. struct sockaddr *hwaddr = addr;
  194. spin_lock_irq(&lp->lock);
  195. set_ether_mac(dev, hwaddr->sa_data);
  196. spin_unlock_irq(&lp->lock);
  197. return(0);
  198. }
  199. static int uml_net_change_mtu(struct net_device *dev, int new_mtu)
  200. {
  201. struct uml_net_private *lp = dev->priv;
  202. int err = 0;
  203. spin_lock_irq(&lp->lock);
  204. new_mtu = (*lp->set_mtu)(new_mtu, &lp->user);
  205. if(new_mtu < 0){
  206. err = new_mtu;
  207. goto out;
  208. }
  209. dev->mtu = new_mtu;
  210. out:
  211. spin_unlock_irq(&lp->lock);
  212. return err;
  213. }
  214. static void uml_net_get_drvinfo(struct net_device *dev,
  215. struct ethtool_drvinfo *info)
  216. {
  217. strcpy(info->driver, DRIVER_NAME);
  218. strcpy(info->version, "42");
  219. }
  220. static struct ethtool_ops uml_net_ethtool_ops = {
  221. .get_drvinfo = uml_net_get_drvinfo,
  222. .get_link = ethtool_op_get_link,
  223. };
  224. void uml_net_user_timer_expire(unsigned long _conn)
  225. {
  226. #ifdef undef
  227. struct connection *conn = (struct connection *)_conn;
  228. dprintk(KERN_INFO "uml_net_user_timer_expire [%p]\n", conn);
  229. do_connect(conn);
  230. #endif
  231. }
  232. static void setup_etheraddr(char *str, unsigned char *addr)
  233. {
  234. char *end;
  235. int i;
  236. if(str == NULL)
  237. goto random;
  238. for(i=0;i<6;i++){
  239. addr[i] = simple_strtoul(str, &end, 16);
  240. if((end == str) ||
  241. ((*end != ':') && (*end != ',') && (*end != '\0'))){
  242. printk(KERN_ERR
  243. "setup_etheraddr: failed to parse '%s' "
  244. "as an ethernet address\n", str);
  245. goto random;
  246. }
  247. str = end + 1;
  248. }
  249. if(addr[0] & 1){
  250. printk(KERN_ERR
  251. "Attempt to assign a broadcast ethernet address to a "
  252. "device disallowed\n");
  253. goto random;
  254. }
  255. return;
  256. random:
  257. random_ether_addr(addr);
  258. }
  259. static DEFINE_SPINLOCK(devices_lock);
  260. static LIST_HEAD(devices);
  261. static struct platform_driver uml_net_driver = {
  262. .driver = {
  263. .name = DRIVER_NAME,
  264. },
  265. };
  266. static int driver_registered;
  267. static int eth_configure(int n, void *init, char *mac,
  268. struct transport *transport)
  269. {
  270. struct uml_net *device;
  271. struct net_device *dev;
  272. struct uml_net_private *lp;
  273. int save, err, size;
  274. size = transport->private_size + sizeof(struct uml_net_private) +
  275. sizeof(((struct uml_net_private *) 0)->user);
  276. device = kzalloc(sizeof(*device), GFP_KERNEL);
  277. if (device == NULL) {
  278. printk(KERN_ERR "eth_configure failed to allocate uml_net\n");
  279. return(1);
  280. }
  281. INIT_LIST_HEAD(&device->list);
  282. device->index = n;
  283. spin_lock(&devices_lock);
  284. list_add(&device->list, &devices);
  285. spin_unlock(&devices_lock);
  286. setup_etheraddr(mac, device->mac);
  287. printk(KERN_INFO "Netdevice %d ", n);
  288. printk("(%02x:%02x:%02x:%02x:%02x:%02x) ",
  289. device->mac[0], device->mac[1],
  290. device->mac[2], device->mac[3],
  291. device->mac[4], device->mac[5]);
  292. printk(": ");
  293. dev = alloc_etherdev(size);
  294. if (dev == NULL) {
  295. printk(KERN_ERR "eth_configure: failed to allocate device\n");
  296. return 1;
  297. }
  298. lp = dev->priv;
  299. /* This points to the transport private data. It's still clear, but we
  300. * must memset it to 0 *now*. Let's help the drivers. */
  301. memset(lp, 0, size);
  302. /* sysfs register */
  303. if (!driver_registered) {
  304. platform_driver_register(&uml_net_driver);
  305. driver_registered = 1;
  306. }
  307. device->pdev.id = n;
  308. device->pdev.name = DRIVER_NAME;
  309. platform_device_register(&device->pdev);
  310. SET_NETDEV_DEV(dev,&device->pdev.dev);
  311. /* If this name ends up conflicting with an existing registered
  312. * netdevice, that is OK, register_netdev{,ice}() will notice this
  313. * and fail.
  314. */
  315. snprintf(dev->name, sizeof(dev->name), "eth%d", n);
  316. device->dev = dev;
  317. (*transport->kern->init)(dev, init);
  318. dev->mtu = transport->user->max_packet;
  319. dev->open = uml_net_open;
  320. dev->hard_start_xmit = uml_net_start_xmit;
  321. dev->stop = uml_net_close;
  322. dev->get_stats = uml_net_get_stats;
  323. dev->set_multicast_list = uml_net_set_multicast_list;
  324. dev->tx_timeout = uml_net_tx_timeout;
  325. dev->set_mac_address = uml_net_set_mac;
  326. dev->change_mtu = uml_net_change_mtu;
  327. dev->ethtool_ops = &uml_net_ethtool_ops;
  328. dev->watchdog_timeo = (HZ >> 1);
  329. dev->irq = UM_ETH_IRQ;
  330. rtnl_lock();
  331. err = register_netdevice(dev);
  332. rtnl_unlock();
  333. if (err) {
  334. device->dev = NULL;
  335. /* XXX: should we call ->remove() here? */
  336. free_netdev(dev);
  337. return 1;
  338. }
  339. /* lp.user is the first four bytes of the transport data, which
  340. * has already been initialized. This structure assignment will
  341. * overwrite that, so we make sure that .user gets overwritten with
  342. * what it already has.
  343. */
  344. save = lp->user[0];
  345. *lp = ((struct uml_net_private)
  346. { .list = LIST_HEAD_INIT(lp->list),
  347. .dev = dev,
  348. .fd = -1,
  349. .mac = { 0xfe, 0xfd, 0x0, 0x0, 0x0, 0x0},
  350. .protocol = transport->kern->protocol,
  351. .open = transport->user->open,
  352. .close = transport->user->close,
  353. .remove = transport->user->remove,
  354. .read = transport->kern->read,
  355. .write = transport->kern->write,
  356. .add_address = transport->user->add_address,
  357. .delete_address = transport->user->delete_address,
  358. .set_mtu = transport->user->set_mtu,
  359. .user = { save } });
  360. init_timer(&lp->tl);
  361. spin_lock_init(&lp->lock);
  362. lp->tl.function = uml_net_user_timer_expire;
  363. memcpy(lp->mac, device->mac, sizeof(lp->mac));
  364. if (transport->user->init)
  365. (*transport->user->init)(&lp->user, dev);
  366. set_ether_mac(dev, device->mac);
  367. return 0;
  368. }
  369. static struct uml_net *find_device(int n)
  370. {
  371. struct uml_net *device;
  372. struct list_head *ele;
  373. spin_lock(&devices_lock);
  374. list_for_each(ele, &devices){
  375. device = list_entry(ele, struct uml_net, list);
  376. if(device->index == n)
  377. goto out;
  378. }
  379. device = NULL;
  380. out:
  381. spin_unlock(&devices_lock);
  382. return(device);
  383. }
  384. static int eth_parse(char *str, int *index_out, char **str_out)
  385. {
  386. char *end;
  387. int n;
  388. n = simple_strtoul(str, &end, 0);
  389. if(end == str){
  390. printk(KERN_ERR "eth_setup: Failed to parse '%s'\n", str);
  391. return(1);
  392. }
  393. if(n < 0){
  394. printk(KERN_ERR "eth_setup: device %d is negative\n", n);
  395. return(1);
  396. }
  397. str = end;
  398. if(*str != '='){
  399. printk(KERN_ERR
  400. "eth_setup: expected '=' after device number\n");
  401. return(1);
  402. }
  403. str++;
  404. if(find_device(n)){
  405. printk(KERN_ERR "eth_setup: Device %d already configured\n",
  406. n);
  407. return(1);
  408. }
  409. if(index_out) *index_out = n;
  410. *str_out = str;
  411. return(0);
  412. }
  413. struct eth_init {
  414. struct list_head list;
  415. char *init;
  416. int index;
  417. };
  418. /* Filled in at boot time. Will need locking if the transports become
  419. * modular.
  420. */
  421. struct list_head transports = LIST_HEAD_INIT(transports);
  422. /* Filled in during early boot */
  423. struct list_head eth_cmd_line = LIST_HEAD_INIT(eth_cmd_line);
  424. static int check_transport(struct transport *transport, char *eth, int n,
  425. void **init_out, char **mac_out)
  426. {
  427. int len;
  428. len = strlen(transport->name);
  429. if(strncmp(eth, transport->name, len))
  430. return(0);
  431. eth += len;
  432. if(*eth == ',')
  433. eth++;
  434. else if(*eth != '\0')
  435. return(0);
  436. *init_out = kmalloc(transport->setup_size, GFP_KERNEL);
  437. if(*init_out == NULL)
  438. return(1);
  439. if(!transport->setup(eth, mac_out, *init_out)){
  440. kfree(*init_out);
  441. *init_out = NULL;
  442. }
  443. return(1);
  444. }
  445. void register_transport(struct transport *new)
  446. {
  447. struct list_head *ele, *next;
  448. struct eth_init *eth;
  449. void *init;
  450. char *mac = NULL;
  451. int match;
  452. list_add(&new->list, &transports);
  453. list_for_each_safe(ele, next, &eth_cmd_line){
  454. eth = list_entry(ele, struct eth_init, list);
  455. match = check_transport(new, eth->init, eth->index, &init,
  456. &mac);
  457. if(!match)
  458. continue;
  459. else if(init != NULL){
  460. eth_configure(eth->index, init, mac, new);
  461. kfree(init);
  462. }
  463. list_del(&eth->list);
  464. }
  465. }
  466. static int eth_setup_common(char *str, int index)
  467. {
  468. struct list_head *ele;
  469. struct transport *transport;
  470. void *init;
  471. char *mac = NULL;
  472. list_for_each(ele, &transports){
  473. transport = list_entry(ele, struct transport, list);
  474. if(!check_transport(transport, str, index, &init, &mac))
  475. continue;
  476. if(init != NULL){
  477. eth_configure(index, init, mac, transport);
  478. kfree(init);
  479. }
  480. return(1);
  481. }
  482. return(0);
  483. }
  484. static int eth_setup(char *str)
  485. {
  486. struct eth_init *new;
  487. int n, err;
  488. err = eth_parse(str, &n, &str);
  489. if(err)
  490. return 1;
  491. new = alloc_bootmem(sizeof(*new));
  492. if (new == NULL){
  493. printk("eth_init : alloc_bootmem failed\n");
  494. return 1;
  495. }
  496. INIT_LIST_HEAD(&new->list);
  497. new->index = n;
  498. new->init = str;
  499. list_add_tail(&new->list, &eth_cmd_line);
  500. return 1;
  501. }
  502. __setup("eth", eth_setup);
  503. __uml_help(eth_setup,
  504. "eth[0-9]+=<transport>,<options>\n"
  505. " Configure a network device.\n\n"
  506. );
  507. #if 0
  508. static int eth_init(void)
  509. {
  510. struct list_head *ele, *next;
  511. struct eth_init *eth;
  512. list_for_each_safe(ele, next, &eth_cmd_line){
  513. eth = list_entry(ele, struct eth_init, list);
  514. if(eth_setup_common(eth->init, eth->index))
  515. list_del(&eth->list);
  516. }
  517. return(1);
  518. }
  519. __initcall(eth_init);
  520. #endif
  521. static int net_config(char *str)
  522. {
  523. int n, err;
  524. err = eth_parse(str, &n, &str);
  525. if(err) return(err);
  526. str = kstrdup(str, GFP_KERNEL);
  527. if(str == NULL){
  528. printk(KERN_ERR "net_config failed to strdup string\n");
  529. return(-1);
  530. }
  531. err = !eth_setup_common(str, n);
  532. if(err)
  533. kfree(str);
  534. return(err);
  535. }
  536. static int net_id(char **str, int *start_out, int *end_out)
  537. {
  538. char *end;
  539. int n;
  540. n = simple_strtoul(*str, &end, 0);
  541. if((*end != '\0') || (end == *str))
  542. return -1;
  543. *start_out = n;
  544. *end_out = n;
  545. *str = end;
  546. return n;
  547. }
  548. static int net_remove(int n)
  549. {
  550. struct uml_net *device;
  551. struct net_device *dev;
  552. struct uml_net_private *lp;
  553. device = find_device(n);
  554. if(device == NULL)
  555. return -ENODEV;
  556. dev = device->dev;
  557. lp = dev->priv;
  558. if(lp->fd > 0)
  559. return -EBUSY;
  560. if(lp->remove != NULL) (*lp->remove)(&lp->user);
  561. unregister_netdev(dev);
  562. platform_device_unregister(&device->pdev);
  563. list_del(&device->list);
  564. kfree(device);
  565. free_netdev(dev);
  566. return 0;
  567. }
  568. static struct mc_device net_mc = {
  569. .name = "eth",
  570. .config = net_config,
  571. .get_config = NULL,
  572. .id = net_id,
  573. .remove = net_remove,
  574. };
  575. static int uml_inetaddr_event(struct notifier_block *this, unsigned long event,
  576. void *ptr)
  577. {
  578. struct in_ifaddr *ifa = ptr;
  579. struct net_device *dev = ifa->ifa_dev->dev;
  580. struct uml_net_private *lp;
  581. void (*proc)(unsigned char *, unsigned char *, void *);
  582. unsigned char addr_buf[4], netmask_buf[4];
  583. if(dev->open != uml_net_open) return(NOTIFY_DONE);
  584. lp = dev->priv;
  585. proc = NULL;
  586. switch (event){
  587. case NETDEV_UP:
  588. proc = lp->add_address;
  589. break;
  590. case NETDEV_DOWN:
  591. proc = lp->delete_address;
  592. break;
  593. }
  594. if(proc != NULL){
  595. memcpy(addr_buf, &ifa->ifa_address, sizeof(addr_buf));
  596. memcpy(netmask_buf, &ifa->ifa_mask, sizeof(netmask_buf));
  597. (*proc)(addr_buf, netmask_buf, &lp->user);
  598. }
  599. return(NOTIFY_DONE);
  600. }
  601. struct notifier_block uml_inetaddr_notifier = {
  602. .notifier_call = uml_inetaddr_event,
  603. };
  604. static int uml_net_init(void)
  605. {
  606. struct list_head *ele;
  607. struct uml_net_private *lp;
  608. struct in_device *ip;
  609. struct in_ifaddr *in;
  610. mconsole_register_dev(&net_mc);
  611. register_inetaddr_notifier(&uml_inetaddr_notifier);
  612. /* Devices may have been opened already, so the uml_inetaddr_notifier
  613. * didn't get a chance to run for them. This fakes it so that
  614. * addresses which have already been set up get handled properly.
  615. */
  616. list_for_each(ele, &opened){
  617. lp = list_entry(ele, struct uml_net_private, list);
  618. ip = lp->dev->ip_ptr;
  619. if(ip == NULL) continue;
  620. in = ip->ifa_list;
  621. while(in != NULL){
  622. uml_inetaddr_event(NULL, NETDEV_UP, in);
  623. in = in->ifa_next;
  624. }
  625. }
  626. return(0);
  627. }
  628. __initcall(uml_net_init);
  629. static void close_devices(void)
  630. {
  631. struct list_head *ele;
  632. struct uml_net_private *lp;
  633. list_for_each(ele, &opened){
  634. lp = list_entry(ele, struct uml_net_private, list);
  635. free_irq(lp->dev->irq, lp->dev);
  636. if((lp->close != NULL) && (lp->fd >= 0))
  637. (*lp->close)(lp->fd, &lp->user);
  638. if(lp->remove != NULL) (*lp->remove)(&lp->user);
  639. }
  640. }
  641. __uml_exitcall(close_devices);
  642. struct sk_buff *ether_adjust_skb(struct sk_buff *skb, int extra)
  643. {
  644. if((skb != NULL) && (skb_tailroom(skb) < extra)){
  645. struct sk_buff *skb2;
  646. skb2 = skb_copy_expand(skb, 0, extra, GFP_ATOMIC);
  647. dev_kfree_skb(skb);
  648. skb = skb2;
  649. }
  650. if(skb != NULL) skb_put(skb, extra);
  651. return(skb);
  652. }
  653. void iter_addresses(void *d, void (*cb)(unsigned char *, unsigned char *,
  654. void *),
  655. void *arg)
  656. {
  657. struct net_device *dev = d;
  658. struct in_device *ip = dev->ip_ptr;
  659. struct in_ifaddr *in;
  660. unsigned char address[4], netmask[4];
  661. if(ip == NULL) return;
  662. in = ip->ifa_list;
  663. while(in != NULL){
  664. memcpy(address, &in->ifa_address, sizeof(address));
  665. memcpy(netmask, &in->ifa_mask, sizeof(netmask));
  666. (*cb)(address, netmask, arg);
  667. in = in->ifa_next;
  668. }
  669. }
  670. int dev_netmask(void *d, void *m)
  671. {
  672. struct net_device *dev = d;
  673. struct in_device *ip = dev->ip_ptr;
  674. struct in_ifaddr *in;
  675. __be32 *mask_out = m;
  676. if(ip == NULL)
  677. return(1);
  678. in = ip->ifa_list;
  679. if(in == NULL)
  680. return(1);
  681. *mask_out = in->ifa_mask;
  682. return(0);
  683. }
  684. void *get_output_buffer(int *len_out)
  685. {
  686. void *ret;
  687. ret = (void *) __get_free_pages(GFP_KERNEL, 0);
  688. if(ret) *len_out = PAGE_SIZE;
  689. else *len_out = 0;
  690. return(ret);
  691. }
  692. void free_output_buffer(void *buffer)
  693. {
  694. free_pages((unsigned long) buffer, 0);
  695. }
  696. int tap_setup_common(char *str, char *type, char **dev_name, char **mac_out,
  697. char **gate_addr)
  698. {
  699. char *remain;
  700. remain = split_if_spec(str, dev_name, mac_out, gate_addr, NULL);
  701. if(remain != NULL){
  702. printk("tap_setup_common - Extra garbage on specification : "
  703. "'%s'\n", remain);
  704. return(1);
  705. }
  706. return(0);
  707. }
  708. unsigned short eth_protocol(struct sk_buff *skb)
  709. {
  710. return(eth_type_trans(skb, skb->dev));
  711. }
  712. /*
  713. * Overrides for Emacs so that we follow Linus's tabbing style.
  714. * Emacs will notice this stuff at the end of the file and automatically
  715. * adjust the settings for this buffer only. This must remain at the end
  716. * of the file.
  717. * ---------------------------------------------------------------------------
  718. * Local variables:
  719. * c-file-style: "linux"
  720. * End:
  721. */