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