net_kern.c 19 KB

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