2005-04-17 02:20:36 +04:00
|
|
|
#ifndef __LINUX_MROUTE_H
|
|
|
|
#define __LINUX_MROUTE_H
|
|
|
|
|
|
|
|
#include <linux/sockios.h>
|
2008-04-03 04:22:52 +04:00
|
|
|
#include <linux/types.h>
|
|
|
|
#ifdef __KERNEL__
|
2005-04-17 02:20:36 +04:00
|
|
|
#include <linux/in.h>
|
2008-04-03 04:22:52 +04:00
|
|
|
#endif
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Based on the MROUTING 3.5 defines primarily to keep
|
|
|
|
* source compatibility with BSD.
|
|
|
|
*
|
|
|
|
* See the mrouted code for the original history.
|
|
|
|
*
|
|
|
|
* Protocol Independent Multicast (PIM) data structures included
|
|
|
|
* Carlos Picoto (cap@di.fc.ul.pt)
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define MRT_BASE 200
|
|
|
|
#define MRT_INIT (MRT_BASE) /* Activate the kernel mroute code */
|
|
|
|
#define MRT_DONE (MRT_BASE+1) /* Shutdown the kernel mroute */
|
|
|
|
#define MRT_ADD_VIF (MRT_BASE+2) /* Add a virtual interface */
|
|
|
|
#define MRT_DEL_VIF (MRT_BASE+3) /* Delete a virtual interface */
|
|
|
|
#define MRT_ADD_MFC (MRT_BASE+4) /* Add a multicast forwarding entry */
|
|
|
|
#define MRT_DEL_MFC (MRT_BASE+5) /* Delete a multicast forwarding entry */
|
|
|
|
#define MRT_VERSION (MRT_BASE+6) /* Get the kernel multicast version */
|
|
|
|
#define MRT_ASSERT (MRT_BASE+7) /* Activate PIM assert mode */
|
ipv4: ipmr: support multiple tables
This patch adds support for multiple independant multicast routing instances,
named "tables".
Userspace multicast routing daemons can bind to a specific table instance by
issuing a setsockopt call using a new option MRT_TABLE. The table number is
stored in the raw socket data and affects all following ipmr setsockopt(),
getsockopt() and ioctl() calls. By default, a single table (RT_TABLE_DEFAULT)
is created with a default routing rule pointing to it. Newly created pimreg
devices have the table number appended ("pimregX"), with the exception of
devices created in the default table, which are named just "pimreg" for
compatibility reasons.
Packets are directed to a specific table instance using routing rules,
similar to how regular routing rules work. Currently iif, oif and mark
are supported as keys, source and destination addresses could be supported
additionally.
Example usage:
- bind pimd/xorp/... to a specific table:
uint32_t table = 123;
setsockopt(fd, IPPROTO_IP, MRT_TABLE, &table, sizeof(table));
- create routing rules directing packets to the new table:
# ip mrule add iif eth0 lookup 123
# ip mrule add oif eth0 lookup 123
Signed-off-by: Patrick McHardy <kaber@trash.net>
Signed-off-by: David S. Miller <davem@davemloft.net>
2010-04-13 09:03:23 +04:00
|
|
|
#define MRT_PIM (MRT_BASE+8) /* enable PIM code */
|
|
|
|
#define MRT_TABLE (MRT_BASE+9) /* Specify mroute table ID */
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
#define SIOCGETVIFCNT SIOCPROTOPRIVATE /* IP protocol privates */
|
|
|
|
#define SIOCGETSGCNT (SIOCPROTOPRIVATE+1)
|
|
|
|
#define SIOCGETRPF (SIOCPROTOPRIVATE+2)
|
|
|
|
|
|
|
|
#define MAXVIFS 32
|
|
|
|
typedef unsigned long vifbitmap_t; /* User mode code depends on this lot */
|
|
|
|
typedef unsigned short vifi_t;
|
|
|
|
#define ALL_VIFS ((vifi_t)(-1))
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Same idea as select
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define VIFM_SET(n,m) ((m)|=(1<<(n)))
|
|
|
|
#define VIFM_CLR(n,m) ((m)&=~(1<<(n)))
|
|
|
|
#define VIFM_ISSET(n,m) ((m)&(1<<(n)))
|
|
|
|
#define VIFM_CLRALL(m) ((m)=0)
|
|
|
|
#define VIFM_COPY(mfrom,mto) ((mto)=(mfrom))
|
|
|
|
#define VIFM_SAME(m1,m2) ((m1)==(m2))
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Passed by mrouted for an MRT_ADD_VIF - again we use the
|
|
|
|
* mrouted 3.6 structures for compatibility
|
|
|
|
*/
|
|
|
|
|
|
|
|
struct vifctl {
|
|
|
|
vifi_t vifc_vifi; /* Index of VIF */
|
|
|
|
unsigned char vifc_flags; /* VIFF_ flags */
|
|
|
|
unsigned char vifc_threshold; /* ttl limit */
|
|
|
|
unsigned int vifc_rate_limit; /* Rate limiter values (NI) */
|
add vif using local interface index instead of IP
When routing daemon wants to enable forwarding of multicast traffic it
performs something like:
struct vifctl vc = {
.vifc_vifi = 1,
.vifc_flags = 0,
.vifc_threshold = 1,
.vifc_rate_limit = 0,
.vifc_lcl_addr = ip, /* <--- ip address of physical
interface, e.g. eth0 */
.vifc_rmt_addr.s_addr = htonl(INADDR_ANY),
};
setsockopt(fd, IPPROTO_IP, MRT_ADD_VIF, &vc, sizeof(vc));
This leads (in the kernel) to calling vif_add() function call which
search the (physical) device using assigned IP address:
dev = ip_dev_find(net, vifc->vifc_lcl_addr.s_addr);
The current API (struct vifctl) does not allow to specify an
interface other way than using it's IP, and if there are more than a
single interface with specified IP only the first one will be found.
The attached patch (against 2.6.30.4) allows to specify an interface
by its index, instead of IP address:
struct vifctl vc = {
.vifc_vifi = 1,
.vifc_flags = VIFF_USE_IFINDEX, /* NEW */
.vifc_threshold = 1,
.vifc_rate_limit = 0,
.vifc_lcl_ifindex = if_nametoindex("eth0"), /* NEW */
.vifc_rmt_addr.s_addr = htonl(INADDR_ANY),
};
setsockopt(fd, IPPROTO_IP, MRT_ADD_VIF, &vc, sizeof(vc));
Signed-off-by: Ilia K. <mail4ilia@gmail.com>
=== modified file 'include/linux/mroute.h'
Signed-off-by: David S. Miller <davem@davemloft.net>
2009-09-16 09:53:07 +04:00
|
|
|
union {
|
|
|
|
struct in_addr vifc_lcl_addr; /* Local interface address */
|
|
|
|
int vifc_lcl_ifindex; /* Local interface index */
|
|
|
|
};
|
2005-04-17 02:20:36 +04:00
|
|
|
struct in_addr vifc_rmt_addr; /* IPIP tunnel addr */
|
|
|
|
};
|
|
|
|
|
add vif using local interface index instead of IP
When routing daemon wants to enable forwarding of multicast traffic it
performs something like:
struct vifctl vc = {
.vifc_vifi = 1,
.vifc_flags = 0,
.vifc_threshold = 1,
.vifc_rate_limit = 0,
.vifc_lcl_addr = ip, /* <--- ip address of physical
interface, e.g. eth0 */
.vifc_rmt_addr.s_addr = htonl(INADDR_ANY),
};
setsockopt(fd, IPPROTO_IP, MRT_ADD_VIF, &vc, sizeof(vc));
This leads (in the kernel) to calling vif_add() function call which
search the (physical) device using assigned IP address:
dev = ip_dev_find(net, vifc->vifc_lcl_addr.s_addr);
The current API (struct vifctl) does not allow to specify an
interface other way than using it's IP, and if there are more than a
single interface with specified IP only the first one will be found.
The attached patch (against 2.6.30.4) allows to specify an interface
by its index, instead of IP address:
struct vifctl vc = {
.vifc_vifi = 1,
.vifc_flags = VIFF_USE_IFINDEX, /* NEW */
.vifc_threshold = 1,
.vifc_rate_limit = 0,
.vifc_lcl_ifindex = if_nametoindex("eth0"), /* NEW */
.vifc_rmt_addr.s_addr = htonl(INADDR_ANY),
};
setsockopt(fd, IPPROTO_IP, MRT_ADD_VIF, &vc, sizeof(vc));
Signed-off-by: Ilia K. <mail4ilia@gmail.com>
=== modified file 'include/linux/mroute.h'
Signed-off-by: David S. Miller <davem@davemloft.net>
2009-09-16 09:53:07 +04:00
|
|
|
#define VIFF_TUNNEL 0x1 /* IPIP tunnel */
|
|
|
|
#define VIFF_SRCRT 0x2 /* NI */
|
|
|
|
#define VIFF_REGISTER 0x4 /* register vif */
|
|
|
|
#define VIFF_USE_IFINDEX 0x8 /* use vifc_lcl_ifindex instead of
|
|
|
|
vifc_lcl_addr to find an interface */
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Cache manipulation structures for mrouted and PIMd
|
|
|
|
*/
|
|
|
|
|
2009-11-04 20:50:58 +03:00
|
|
|
struct mfcctl {
|
2005-04-17 02:20:36 +04:00
|
|
|
struct in_addr mfcc_origin; /* Origin of mcast */
|
|
|
|
struct in_addr mfcc_mcastgrp; /* Group in question */
|
|
|
|
vifi_t mfcc_parent; /* Where it arrived */
|
|
|
|
unsigned char mfcc_ttls[MAXVIFS]; /* Where it is going */
|
|
|
|
unsigned int mfcc_pkt_cnt; /* pkt count for src-grp */
|
|
|
|
unsigned int mfcc_byte_cnt;
|
|
|
|
unsigned int mfcc_wrong_if;
|
|
|
|
int mfcc_expire;
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Group count retrieval for mrouted
|
|
|
|
*/
|
|
|
|
|
2009-11-04 20:50:58 +03:00
|
|
|
struct sioc_sg_req {
|
2005-04-17 02:20:36 +04:00
|
|
|
struct in_addr src;
|
|
|
|
struct in_addr grp;
|
|
|
|
unsigned long pktcnt;
|
|
|
|
unsigned long bytecnt;
|
|
|
|
unsigned long wrong_if;
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* To get vif packet counts
|
|
|
|
*/
|
|
|
|
|
2009-11-04 20:50:58 +03:00
|
|
|
struct sioc_vif_req {
|
2005-04-17 02:20:36 +04:00
|
|
|
vifi_t vifi; /* Which iface */
|
|
|
|
unsigned long icount; /* In packets */
|
|
|
|
unsigned long ocount; /* Out packets */
|
|
|
|
unsigned long ibytes; /* In bytes */
|
|
|
|
unsigned long obytes; /* Out bytes */
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This is the format the mroute daemon expects to see IGMP control
|
|
|
|
* data. Magically happens to be like an IP packet as per the original
|
|
|
|
*/
|
|
|
|
|
2009-11-04 20:50:58 +03:00
|
|
|
struct igmpmsg {
|
2005-04-17 02:20:36 +04:00
|
|
|
__u32 unused1,unused2;
|
|
|
|
unsigned char im_msgtype; /* What is this */
|
|
|
|
unsigned char im_mbz; /* Must be zero */
|
|
|
|
unsigned char im_vif; /* Interface (this ought to be a vifi_t!) */
|
|
|
|
unsigned char unused3;
|
|
|
|
struct in_addr im_src,im_dst;
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* That's all usermode folks
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef __KERNEL__
|
2008-08-30 01:37:23 +04:00
|
|
|
#include <linux/pim.h>
|
2005-04-17 02:20:36 +04:00
|
|
|
#include <net/sock.h>
|
|
|
|
|
2007-11-06 08:32:31 +03:00
|
|
|
#ifdef CONFIG_IP_MROUTE
|
|
|
|
static inline int ip_mroute_opt(int opt)
|
|
|
|
{
|
|
|
|
return (opt >= MRT_BASE) && (opt <= MRT_BASE + 10);
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
static inline int ip_mroute_opt(int opt)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2008-07-03 11:51:22 +04:00
|
|
|
#ifdef CONFIG_IP_MROUTE
|
2009-10-01 03:12:20 +04:00
|
|
|
extern int ip_mroute_setsockopt(struct sock *, int, char __user *, unsigned int);
|
2005-04-17 02:20:36 +04:00
|
|
|
extern int ip_mroute_getsockopt(struct sock *, int, char __user *, int __user *);
|
|
|
|
extern int ipmr_ioctl(struct sock *sk, int cmd, void __user *arg);
|
2011-01-29 19:15:56 +03:00
|
|
|
extern int ipmr_compat_ioctl(struct sock *sk, unsigned int cmd, void __user *arg);
|
2008-07-03 08:13:36 +04:00
|
|
|
extern int ip_mr_init(void);
|
2008-07-03 11:51:22 +04:00
|
|
|
#else
|
|
|
|
static inline
|
|
|
|
int ip_mroute_setsockopt(struct sock *sock,
|
2009-10-01 03:12:20 +04:00
|
|
|
int optname, char __user *optval, unsigned int optlen)
|
2008-07-03 11:51:22 +04:00
|
|
|
{
|
|
|
|
return -ENOPROTOOPT;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline
|
|
|
|
int ip_mroute_getsockopt(struct sock *sock,
|
|
|
|
int optname, char __user *optval, int __user *optlen)
|
|
|
|
{
|
|
|
|
return -ENOPROTOOPT;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline
|
|
|
|
int ipmr_ioctl(struct sock *sk, int cmd, void __user *arg)
|
|
|
|
{
|
|
|
|
return -ENOIOCTLCMD;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int ip_mr_init(void)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2009-11-04 20:50:58 +03:00
|
|
|
struct vif_device {
|
2005-04-17 02:20:36 +04:00
|
|
|
struct net_device *dev; /* Device we are using */
|
|
|
|
unsigned long bytes_in,bytes_out;
|
|
|
|
unsigned long pkt_in,pkt_out; /* Statistics */
|
|
|
|
unsigned long rate_limit; /* Traffic shaping (NI) */
|
|
|
|
unsigned char threshold; /* TTL threshold */
|
|
|
|
unsigned short flags; /* Control flags */
|
2006-09-28 05:39:29 +04:00
|
|
|
__be32 local,remote; /* Addresses(remote for tunnels)*/
|
2005-04-17 02:20:36 +04:00
|
|
|
int link; /* Physical interface index */
|
|
|
|
};
|
|
|
|
|
|
|
|
#define VIFF_STATIC 0x8000
|
|
|
|
|
2009-11-04 20:50:58 +03:00
|
|
|
struct mfc_cache {
|
2010-04-13 09:03:21 +04:00
|
|
|
struct list_head list;
|
2006-09-28 05:39:29 +04:00
|
|
|
__be32 mfc_mcastgrp; /* Group the entry belongs to */
|
|
|
|
__be32 mfc_origin; /* Source of packet */
|
2005-04-17 02:20:36 +04:00
|
|
|
vifi_t mfc_parent; /* Source interface */
|
|
|
|
int mfc_flags; /* Flags on line */
|
|
|
|
|
|
|
|
union {
|
|
|
|
struct {
|
|
|
|
unsigned long expires;
|
|
|
|
struct sk_buff_head unresolved; /* Unresolved buffers */
|
|
|
|
} unres;
|
|
|
|
struct {
|
|
|
|
unsigned long last_assert;
|
|
|
|
int minvif;
|
|
|
|
int maxvif;
|
|
|
|
unsigned long bytes;
|
|
|
|
unsigned long pkt;
|
|
|
|
unsigned long wrong_if;
|
|
|
|
unsigned char ttls[MAXVIFS]; /* TTL thresholds */
|
|
|
|
} res;
|
|
|
|
} mfc_un;
|
2010-10-01 20:15:08 +04:00
|
|
|
struct rcu_head rcu;
|
2005-04-17 02:20:36 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
#define MFC_STATIC 1
|
|
|
|
#define MFC_NOTIFY 2
|
|
|
|
|
|
|
|
#define MFC_LINES 64
|
|
|
|
|
|
|
|
#ifdef __BIG_ENDIAN
|
2006-09-28 05:39:29 +04:00
|
|
|
#define MFC_HASH(a,b) (((((__force u32)(__be32)a)>>24)^(((__force u32)(__be32)b)>>26))&(MFC_LINES-1))
|
2005-04-17 02:20:36 +04:00
|
|
|
#else
|
2006-09-28 05:39:29 +04:00
|
|
|
#define MFC_HASH(a,b) ((((__force u32)(__be32)a)^(((__force u32)(__be32)b)>>2))&(MFC_LINES-1))
|
2005-04-17 02:20:36 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
#define MFC_ASSERT_THRESH (3*HZ) /* Maximal freq. of asserts */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Pseudo messages used by mrouted
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define IGMPMSG_NOCACHE 1 /* Kern cache fill request to mrouted */
|
|
|
|
#define IGMPMSG_WRONGVIF 2 /* For PIM assert processing (unused) */
|
|
|
|
#define IGMPMSG_WHOLEPKT 3 /* For PIM Register processing */
|
|
|
|
|
|
|
|
#ifdef __KERNEL__
|
|
|
|
struct rtmsg;
|
2009-01-22 07:56:23 +03:00
|
|
|
extern int ipmr_get_route(struct net *net, struct sk_buff *skb,
|
2011-05-04 23:18:54 +04:00
|
|
|
__be32 saddr, __be32 daddr,
|
2009-01-22 07:56:23 +03:00
|
|
|
struct rtmsg *rtm, int nowait);
|
2005-04-17 02:20:36 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|