divert.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /*
  2. * Frame Diversion, Benoit Locher <Benoit.Locher@skf.com>
  3. *
  4. * Changes:
  5. * 06/09/2000 BL: initial version
  6. *
  7. */
  8. #ifndef _LINUX_DIVERT_H
  9. #define _LINUX_DIVERT_H
  10. #include <asm/types.h>
  11. #define MAX_DIVERT_PORTS 8 /* Max number of ports to divert (tcp, udp) */
  12. /* Divertable protocols */
  13. #define DIVERT_PROTO_NONE 0x0000
  14. #define DIVERT_PROTO_IP 0x0001
  15. #define DIVERT_PROTO_ICMP 0x0002
  16. #define DIVERT_PROTO_TCP 0x0004
  17. #define DIVERT_PROTO_UDP 0x0008
  18. /*
  19. * This is an Ethernet Frame Diverter option block
  20. */
  21. struct divert_blk
  22. {
  23. int divert; /* are we active */
  24. unsigned int protos; /* protocols */
  25. u16 tcp_dst[MAX_DIVERT_PORTS]; /* specific tcp dst ports to divert */
  26. u16 tcp_src[MAX_DIVERT_PORTS]; /* specific tcp src ports to divert */
  27. u16 udp_dst[MAX_DIVERT_PORTS]; /* specific udp dst ports to divert */
  28. u16 udp_src[MAX_DIVERT_PORTS]; /* specific udp src ports to divert */
  29. };
  30. /*
  31. * Diversion control block, for configuration with the userspace tool
  32. * divert
  33. */
  34. typedef union _divert_cf_arg
  35. {
  36. s16 int16;
  37. u16 uint16;
  38. s32 int32;
  39. u32 uint32;
  40. s64 int64;
  41. u64 uint64;
  42. void __user *ptr;
  43. } divert_cf_arg;
  44. struct divert_cf
  45. {
  46. int cmd; /* Command */
  47. divert_cf_arg arg1,
  48. arg2,
  49. arg3;
  50. int dev_index; /* device index (eth0=0, etc...) */
  51. };
  52. /* Diversion commands */
  53. #define DIVCMD_DIVERT 1 /* ENABLE/DISABLE diversion */
  54. #define DIVCMD_IP 2 /* ENABLE/DISABLE whold IP diversion */
  55. #define DIVCMD_TCP 3 /* ENABLE/DISABLE whold TCP diversion */
  56. #define DIVCMD_TCPDST 4 /* ADD/REMOVE TCP DST port for diversion */
  57. #define DIVCMD_TCPSRC 5 /* ADD/REMOVE TCP SRC port for diversion */
  58. #define DIVCMD_UDP 6 /* ENABLE/DISABLE whole UDP diversion */
  59. #define DIVCMD_UDPDST 7 /* ADD/REMOVE UDP DST port for diversion */
  60. #define DIVCMD_UDPSRC 8 /* ADD/REMOVE UDP SRC port for diversion */
  61. #define DIVCMD_ICMP 9 /* ENABLE/DISABLE whole ICMP diversion */
  62. #define DIVCMD_GETSTATUS 10 /* GET the status of the diverter */
  63. #define DIVCMD_RESET 11 /* Reset the diverter on the specified dev */
  64. #define DIVCMD_GETVERSION 12 /* Retrieve the diverter code version (char[32]) */
  65. /* General syntax of the commands:
  66. *
  67. * DIVCMD_xxxxxx(arg1, arg2, arg3, dev_index)
  68. *
  69. * SIOCSIFDIVERT:
  70. * DIVCMD_DIVERT(DIVARG1_ENABLE|DIVARG1_DISABLE, , ,ifindex)
  71. * DIVCMD_IP(DIVARG1_ENABLE|DIVARG1_DISABLE, , , ifindex)
  72. * DIVCMD_TCP(DIVARG1_ENABLE|DIVARG1_DISABLE, , , ifindex)
  73. * DIVCMD_TCPDST(DIVARG1_ADD|DIVARG1_REMOVE, port, , ifindex)
  74. * DIVCMD_TCPSRC(DIVARG1_ADD|DIVARG1_REMOVE, port, , ifindex)
  75. * DIVCMD_UDP(DIVARG1_ENABLE|DIVARG1_DISABLE, , , ifindex)
  76. * DIVCMD_UDPDST(DIVARG1_ADD|DIVARG1_REMOVE, port, , ifindex)
  77. * DIVCMD_UDPSRC(DIVARG1_ADD|DIVARG1_REMOVE, port, , ifindex)
  78. * DIVCMD_ICMP(DIVARG1_ENABLE|DIVARG1_DISABLE, , , ifindex)
  79. * DIVCMD_RESET(, , , ifindex)
  80. *
  81. * SIOGIFDIVERT:
  82. * DIVCMD_GETSTATUS(divert_blk, , , ifindex)
  83. * DIVCMD_GETVERSION(string[3])
  84. */
  85. /* Possible values for arg1 */
  86. #define DIVARG1_ENABLE 0 /* ENABLE something */
  87. #define DIVARG1_DISABLE 1 /* DISABLE something */
  88. #define DIVARG1_ADD 2 /* ADD something */
  89. #define DIVARG1_REMOVE 3 /* REMOVE something */
  90. #ifdef __KERNEL__
  91. /* diverter functions */
  92. #include <linux/skbuff.h>
  93. #ifdef CONFIG_NET_DIVERT
  94. #include <linux/netdevice.h>
  95. int alloc_divert_blk(struct net_device *);
  96. void free_divert_blk(struct net_device *);
  97. int divert_ioctl(unsigned int cmd, struct divert_cf __user *arg);
  98. void divert_frame(struct sk_buff *skb);
  99. static inline void handle_diverter(struct sk_buff *skb)
  100. {
  101. /* if diversion is supported on device, then divert */
  102. if (skb->dev->divert && skb->dev->divert->divert)
  103. divert_frame(skb);
  104. }
  105. #else
  106. # define alloc_divert_blk(dev) (0)
  107. # define free_divert_blk(dev) do {} while (0)
  108. # define divert_ioctl(cmd, arg) (-ENOPKG)
  109. # define handle_diverter(skb) do {} while (0)
  110. #endif
  111. #endif
  112. #endif /* _LINUX_DIVERT_H */