2017-11-01 15:07:57 +01:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0 */
|
2005-04-16 15:20:36 -07:00
|
|
|
/*
|
|
|
|
|
*
|
|
|
|
|
* Generic internet FLOW.
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#ifndef _NET_FLOW_H
|
|
|
|
|
#define _NET_FLOW_H
|
|
|
|
|
|
|
|
|
|
#include <linux/in6.h>
|
2011-07-26 16:09:06 -07:00
|
|
|
#include <linux/atomic.h>
|
2023-01-25 23:14:24 -08:00
|
|
|
#include <linux/container_of.h>
|
2016-11-04 02:23:42 +09:00
|
|
|
#include <linux/uidgid.h>
|
2025-08-25 15:37:43 +02:00
|
|
|
#include <net/inet_dscp.h>
|
2005-04-16 15:20:36 -07:00
|
|
|
|
2023-01-25 23:14:24 -08:00
|
|
|
struct flow_keys;
|
|
|
|
|
|
2014-04-15 16:25:34 -07:00
|
|
|
/*
|
|
|
|
|
* ifindex generation is per-net namespace, and loopback is
|
|
|
|
|
* always the 1st device in ns (see net_dev_init), thus any
|
|
|
|
|
* loopback device should get ifindex 1
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#define LOOPBACK_IFINDEX 1
|
|
|
|
|
|
2015-07-21 10:43:59 +02:00
|
|
|
struct flowi_tunnel {
|
|
|
|
|
__be64 tun_id;
|
|
|
|
|
};
|
|
|
|
|
|
2011-03-11 18:22:00 -05:00
|
|
|
struct flowi_common {
|
|
|
|
|
int flowic_oif;
|
|
|
|
|
int flowic_iif;
|
2022-03-14 14:45:51 -06:00
|
|
|
int flowic_l3mdev;
|
2011-03-11 18:22:00 -05:00
|
|
|
__u32 flowic_mark;
|
2025-08-25 15:37:43 +02:00
|
|
|
dscp_t flowic_dscp;
|
2011-03-11 18:22:00 -05:00
|
|
|
__u8 flowic_scope;
|
|
|
|
|
__u8 flowic_proto;
|
|
|
|
|
__u8 flowic_flags;
|
2011-03-11 15:55:37 -05:00
|
|
|
#define FLOWI_FLAG_ANYSRC 0x01
|
2013-08-28 08:04:14 +02:00
|
|
|
#define FLOWI_FLAG_KNOWN_NH 0x02
|
2025-04-14 20:20:21 +03:00
|
|
|
#define FLOWI_FLAG_L3MDEV_OIF 0x04
|
2025-04-24 10:35:19 -04:00
|
|
|
#define FLOWI_FLAG_ANY_SPORT 0x08
|
2011-03-11 18:22:00 -05:00
|
|
|
__u32 flowic_secid;
|
2016-11-04 02:23:42 +09:00
|
|
|
kuid_t flowic_uid;
|
2019-02-24 11:36:20 +08:00
|
|
|
__u32 flowic_multipath_hash;
|
2023-10-25 14:10:37 +00:00
|
|
|
struct flowi_tunnel flowic_tun_key;
|
2011-03-11 18:22:00 -05:00
|
|
|
};
|
|
|
|
|
|
2011-03-11 18:36:42 -05:00
|
|
|
union flowi_uli {
|
|
|
|
|
struct {
|
|
|
|
|
__be16 dport;
|
2011-03-31 18:03:35 -07:00
|
|
|
__be16 sport;
|
2011-03-11 18:36:42 -05:00
|
|
|
} ports;
|
|
|
|
|
|
|
|
|
|
struct {
|
|
|
|
|
__u8 type;
|
|
|
|
|
__u8 code;
|
|
|
|
|
} icmpt;
|
|
|
|
|
|
|
|
|
|
__be32 gre_key;
|
|
|
|
|
|
|
|
|
|
struct {
|
|
|
|
|
__u8 type;
|
|
|
|
|
} mht;
|
|
|
|
|
};
|
|
|
|
|
|
2011-03-12 00:44:35 -05:00
|
|
|
struct flowi4 {
|
2011-03-11 18:22:00 -05:00
|
|
|
struct flowi_common __fl_common;
|
2011-03-11 19:54:08 -05:00
|
|
|
#define flowi4_oif __fl_common.flowic_oif
|
|
|
|
|
#define flowi4_iif __fl_common.flowic_iif
|
2022-03-14 14:45:51 -06:00
|
|
|
#define flowi4_l3mdev __fl_common.flowic_l3mdev
|
2011-03-11 19:54:08 -05:00
|
|
|
#define flowi4_mark __fl_common.flowic_mark
|
2025-08-25 15:37:43 +02:00
|
|
|
#define flowi4_dscp __fl_common.flowic_dscp
|
2011-03-11 19:54:08 -05:00
|
|
|
#define flowi4_scope __fl_common.flowic_scope
|
|
|
|
|
#define flowi4_proto __fl_common.flowic_proto
|
|
|
|
|
#define flowi4_flags __fl_common.flowic_flags
|
|
|
|
|
#define flowi4_secid __fl_common.flowic_secid
|
2015-07-21 10:43:59 +02:00
|
|
|
#define flowi4_tun_key __fl_common.flowic_tun_key
|
2016-11-04 02:23:42 +09:00
|
|
|
#define flowi4_uid __fl_common.flowic_uid
|
2019-02-24 11:36:20 +08:00
|
|
|
#define flowi4_multipath_hash __fl_common.flowic_multipath_hash
|
2011-11-30 19:00:53 +00:00
|
|
|
|
|
|
|
|
/* (saddr,daddr) must be grouped, same order as in IP header */
|
2011-03-12 00:44:35 -05:00
|
|
|
__be32 saddr;
|
2011-11-30 19:00:53 +00:00
|
|
|
__be32 daddr;
|
|
|
|
|
|
2011-03-12 00:44:35 -05:00
|
|
|
union flowi_uli uli;
|
2011-03-12 03:00:33 -05:00
|
|
|
#define fl4_sport uli.ports.sport
|
|
|
|
|
#define fl4_dport uli.ports.dport
|
|
|
|
|
#define fl4_icmp_type uli.icmpt.type
|
|
|
|
|
#define fl4_icmp_code uli.icmpt.code
|
|
|
|
|
#define fl4_mh_type uli.mht.type
|
|
|
|
|
#define fl4_gre_key uli.gre_key
|
2011-09-05 16:47:23 +00:00
|
|
|
} __attribute__((__aligned__(BITS_PER_LONG/8)));
|
2005-04-16 15:20:36 -07:00
|
|
|
|
2011-03-31 04:52:14 -07:00
|
|
|
static inline void flowi4_init_output(struct flowi4 *fl4, int oif,
|
|
|
|
|
__u32 mark, __u8 tos, __u8 scope,
|
|
|
|
|
__u8 proto, __u8 flags,
|
|
|
|
|
__be32 daddr, __be32 saddr,
|
2016-11-04 02:23:43 +09:00
|
|
|
__be16 dport, __be16 sport,
|
|
|
|
|
kuid_t uid)
|
2011-03-31 04:52:14 -07:00
|
|
|
{
|
|
|
|
|
fl4->flowi4_oif = oif;
|
2014-04-15 16:25:34 -07:00
|
|
|
fl4->flowi4_iif = LOOPBACK_IFINDEX;
|
2022-03-14 14:45:51 -06:00
|
|
|
fl4->flowi4_l3mdev = 0;
|
2011-03-31 04:52:14 -07:00
|
|
|
fl4->flowi4_mark = mark;
|
2025-08-25 15:37:43 +02:00
|
|
|
fl4->flowi4_dscp = inet_dsfield_to_dscp(tos);
|
2011-03-31 04:52:14 -07:00
|
|
|
fl4->flowi4_scope = scope;
|
|
|
|
|
fl4->flowi4_proto = proto;
|
|
|
|
|
fl4->flowi4_flags = flags;
|
|
|
|
|
fl4->flowi4_secid = 0;
|
2015-07-21 10:43:59 +02:00
|
|
|
fl4->flowi4_tun_key.tun_id = 0;
|
2016-11-04 02:23:43 +09:00
|
|
|
fl4->flowi4_uid = uid;
|
2011-03-31 04:52:14 -07:00
|
|
|
fl4->daddr = daddr;
|
|
|
|
|
fl4->saddr = saddr;
|
|
|
|
|
fl4->fl4_dport = dport;
|
2011-03-31 18:03:35 -07:00
|
|
|
fl4->fl4_sport = sport;
|
2020-09-13 12:43:39 -06:00
|
|
|
fl4->flowi4_multipath_hash = 0;
|
2011-03-31 04:52:14 -07:00
|
|
|
}
|
2012-02-04 13:04:46 +00:00
|
|
|
|
|
|
|
|
/* Reset some input parameters after previous lookup */
|
2023-06-01 18:37:46 +02:00
|
|
|
static inline void flowi4_update_output(struct flowi4 *fl4, int oif,
|
2012-02-04 13:04:46 +00:00
|
|
|
__be32 daddr, __be32 saddr)
|
|
|
|
|
{
|
|
|
|
|
fl4->flowi4_oif = oif;
|
|
|
|
|
fl4->daddr = daddr;
|
|
|
|
|
fl4->saddr = saddr;
|
|
|
|
|
}
|
2018-02-27 15:48:21 -08:00
|
|
|
|
2011-03-31 04:52:14 -07:00
|
|
|
|
2011-03-12 00:44:35 -05:00
|
|
|
struct flowi6 {
|
|
|
|
|
struct flowi_common __fl_common;
|
2011-03-12 02:30:50 -05:00
|
|
|
#define flowi6_oif __fl_common.flowic_oif
|
|
|
|
|
#define flowi6_iif __fl_common.flowic_iif
|
2022-03-14 14:45:51 -06:00
|
|
|
#define flowi6_l3mdev __fl_common.flowic_l3mdev
|
2011-03-12 02:30:50 -05:00
|
|
|
#define flowi6_mark __fl_common.flowic_mark
|
|
|
|
|
#define flowi6_scope __fl_common.flowic_scope
|
|
|
|
|
#define flowi6_proto __fl_common.flowic_proto
|
|
|
|
|
#define flowi6_flags __fl_common.flowic_flags
|
|
|
|
|
#define flowi6_secid __fl_common.flowic_secid
|
2015-08-20 13:56:31 +02:00
|
|
|
#define flowi6_tun_key __fl_common.flowic_tun_key
|
2016-11-04 02:23:42 +09:00
|
|
|
#define flowi6_uid __fl_common.flowic_uid
|
2011-03-12 00:44:35 -05:00
|
|
|
struct in6_addr daddr;
|
|
|
|
|
struct in6_addr saddr;
|
2025-08-25 15:37:43 +02:00
|
|
|
/* Note: flowi6_dscp is encoded in flowlabel, too. */
|
2011-03-12 00:44:35 -05:00
|
|
|
__be32 flowlabel;
|
|
|
|
|
union flowi_uli uli;
|
2011-03-12 16:36:19 -05:00
|
|
|
#define fl6_sport uli.ports.sport
|
|
|
|
|
#define fl6_dport uli.ports.dport
|
|
|
|
|
#define fl6_icmp_type uli.icmpt.type
|
|
|
|
|
#define fl6_icmp_code uli.icmpt.code
|
|
|
|
|
#define fl6_mh_type uli.mht.type
|
|
|
|
|
#define fl6_gre_key uli.gre_key
|
2017-08-23 09:58:28 +02:00
|
|
|
__u32 mp_hash;
|
2011-09-05 16:47:23 +00:00
|
|
|
} __attribute__((__aligned__(BITS_PER_LONG/8)));
|
2011-03-12 00:44:35 -05:00
|
|
|
|
|
|
|
|
struct flowi {
|
2005-04-16 15:20:36 -07:00
|
|
|
union {
|
2011-03-12 00:44:35 -05:00
|
|
|
struct flowi_common __fl_common;
|
|
|
|
|
struct flowi4 ip4;
|
|
|
|
|
struct flowi6 ip6;
|
|
|
|
|
} u;
|
|
|
|
|
#define flowi_oif u.__fl_common.flowic_oif
|
|
|
|
|
#define flowi_iif u.__fl_common.flowic_iif
|
2022-03-14 14:45:51 -06:00
|
|
|
#define flowi_l3mdev u.__fl_common.flowic_l3mdev
|
2011-03-12 00:44:35 -05:00
|
|
|
#define flowi_mark u.__fl_common.flowic_mark
|
2025-08-25 15:37:43 +02:00
|
|
|
#define flowi_dscp u.__fl_common.flowic_dscp
|
2011-03-12 00:44:35 -05:00
|
|
|
#define flowi_scope u.__fl_common.flowic_scope
|
|
|
|
|
#define flowi_proto u.__fl_common.flowic_proto
|
|
|
|
|
#define flowi_flags u.__fl_common.flowic_flags
|
|
|
|
|
#define flowi_secid u.__fl_common.flowic_secid
|
2015-07-21 10:43:59 +02:00
|
|
|
#define flowi_tun_key u.__fl_common.flowic_tun_key
|
2016-11-04 02:23:42 +09:00
|
|
|
#define flowi_uid u.__fl_common.flowic_uid
|
2005-04-16 15:20:36 -07:00
|
|
|
} __attribute__((__aligned__(BITS_PER_LONG/8)));
|
|
|
|
|
|
2011-03-11 19:23:02 -05:00
|
|
|
static inline struct flowi *flowi4_to_flowi(struct flowi4 *fl4)
|
|
|
|
|
{
|
|
|
|
|
return container_of(fl4, struct flowi, u.ip4);
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-27 22:38:26 -04:00
|
|
|
static inline struct flowi_common *flowi4_to_flowi_common(struct flowi4 *fl4)
|
|
|
|
|
{
|
2021-09-02 14:36:17 +09:00
|
|
|
return &(fl4->__fl_common);
|
2020-09-27 22:38:26 -04:00
|
|
|
}
|
|
|
|
|
|
2011-03-11 19:23:02 -05:00
|
|
|
static inline struct flowi *flowi6_to_flowi(struct flowi6 *fl6)
|
|
|
|
|
{
|
|
|
|
|
return container_of(fl6, struct flowi, u.ip6);
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-27 22:38:26 -04:00
|
|
|
static inline struct flowi_common *flowi6_to_flowi_common(struct flowi6 *fl6)
|
|
|
|
|
{
|
2021-09-02 14:36:17 +09:00
|
|
|
return &(fl6->__fl_common);
|
2020-09-27 22:38:26 -04:00
|
|
|
}
|
|
|
|
|
|
2015-09-01 21:19:17 -07:00
|
|
|
__u32 __get_hash_from_flowi6(const struct flowi6 *fl6, struct flow_keys *keys);
|
2015-09-01 09:24:25 -07:00
|
|
|
|
2005-04-16 15:20:36 -07:00
|
|
|
#endif
|