ethersink.c 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /*
  2. * An ethernet /dev/null.
  3. * Useful as a bridging target with ethernet-based VPN.
  4. */
  5. #include "u.h"
  6. #include "../port/lib.h"
  7. #include "mem.h"
  8. #include "dat.h"
  9. #include "fns.h"
  10. #include "io.h"
  11. #include "../port/error.h"
  12. #include "../port/netif.h"
  13. #include "etherif.h"
  14. static long
  15. ctl(Ether *ether, void *buf, long n)
  16. {
  17. uchar ea[Eaddrlen];
  18. Cmdbuf *cb;
  19. cb = parsecmd(buf, n);
  20. if(cb->nf >= 2
  21. && strcmp(cb->f[0], "ea")==0
  22. && parseether(ea, cb->f[1]) == 0){
  23. free(cb);
  24. memmove(ether->ea, ea, Eaddrlen);
  25. memmove(ether->addr, ether->ea, Eaddrlen);
  26. return 0;
  27. }
  28. free(cb);
  29. error(Ebadctl);
  30. return -1; /* not reached */
  31. }
  32. static void
  33. nop(Ether*)
  34. {
  35. }
  36. static int
  37. reset(Ether* ether)
  38. {
  39. uchar ea[Eaddrlen];
  40. if(ether->type==nil)
  41. return -1;
  42. memset(ea, 0, sizeof ea);
  43. ether->mbps = 1000;
  44. ether->attach = nop;
  45. ether->transmit = nop;
  46. ether->irq = -1;
  47. ether->interrupt = nil;
  48. ether->ifstat = nil;
  49. ether->ctl = ctl;
  50. ether->promiscuous = nil;
  51. ether->multicast = nil;
  52. ether->arg = ether;
  53. return 0;
  54. }
  55. void
  56. ethersinklink(void)
  57. {
  58. addethercard("sink", reset);
  59. }