Skip to content

Commit 5a0fd98

Browse files
committed
Merge branch 'ife-to-module'
Yotam Gigi says: ==================== Extract IFE logic to module Extract ife logic from the tc_ife action into an independent module, and make the tc_ife action use it. This way, the ife encapsulation can be used by other modules other than tc_ife action. v1->v2: Fix duplicate symbol error by introducing a new patch that makes the original symbol static. The symbol ife_tlv_meta_extract is exported in act_ife, though not being used by any other module. As the symbol is being moved to the new ife module, introducing the new module creates duplicate symbol. To fix it, add a new patch (1/3) that makes the ife_tlv_meta_extract symbol static in act_ife, thus the symbol does not collide. ==================== Signed-off-by: David S. Miller <[email protected]>
2 parents 3541f9e + 295a6e0 commit 5a0fd98

File tree

13 files changed

+276
-90
lines changed

13 files changed

+276
-90
lines changed

MAINTAINERS

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6250,6 +6250,13 @@ F: include/net/cfg802154.h
62506250
F: include/net/ieee802154_netdev.h
62516251
F: Documentation/networking/ieee802154.txt
62526252

6253+
IFE PROTOCOL
6254+
M: Yotam Gigi <[email protected]>
6255+
M: Jamal Hadi Salim <[email protected]>
6256+
F: net/ife
6257+
F: include/net/ife.h
6258+
F: include/uapi/linux/ife.h
6259+
62536260
IGORPLUG-USB IR RECEIVER
62546261
M: Sean Young <[email protected]>
62556262

include/net/ife.h

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#ifndef __NET_IFE_H
2+
#define __NET_IFE_H
3+
4+
#include <linux/etherdevice.h>
5+
#include <linux/rtnetlink.h>
6+
#include <linux/module.h>
7+
#include <uapi/linux/ife.h>
8+
9+
#if IS_ENABLED(CONFIG_NET_IFE)
10+
11+
void *ife_encode(struct sk_buff *skb, u16 metalen);
12+
void *ife_decode(struct sk_buff *skb, u16 *metalen);
13+
14+
void *ife_tlv_meta_decode(void *skbdata, u16 *attrtype, u16 *dlen, u16 *totlen);
15+
int ife_tlv_meta_encode(void *skbdata, u16 attrtype, u16 dlen,
16+
const void *dval);
17+
18+
void *ife_tlv_meta_next(void *skbdata);
19+
20+
#else
21+
22+
static inline void *ife_encode(struct sk_buff *skb, u16 metalen)
23+
{
24+
return NULL;
25+
}
26+
27+
static inline void *ife_decode(struct sk_buff *skb, u16 *metalen)
28+
{
29+
return NULL;
30+
}
31+
32+
static inline void *ife_tlv_meta_decode(void *skbdata, u16 *attrtype, u16 *dlen,
33+
u16 *totlen)
34+
{
35+
return NULL;
36+
}
37+
38+
static inline int ife_tlv_meta_encode(void *skbdata, u16 attrtype, u16 dlen,
39+
const void *dval)
40+
{
41+
return 0;
42+
}
43+
44+
static inline void *ife_tlv_meta_next(void *skbdata)
45+
{
46+
return NULL;
47+
}
48+
49+
#endif
50+
51+
#endif /* __NET_IFE_H */

include/net/tc_act/tc_ife.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
#include <linux/rtnetlink.h>
77
#include <linux/module.h>
88

9-
#define IFE_METAHDRLEN 2
109
struct tcf_ife_info {
1110
struct tc_action common;
1211
u8 eth_dst[ETH_ALEN];
@@ -45,8 +44,6 @@ struct tcf_meta_ops {
4544

4645
int ife_get_meta_u32(struct sk_buff *skb, struct tcf_meta_info *mi);
4746
int ife_get_meta_u16(struct sk_buff *skb, struct tcf_meta_info *mi);
48-
int ife_tlv_meta_encode(void *skbdata, u16 attrtype, u16 dlen,
49-
const void *dval);
5047
int ife_alloc_meta_u32(struct tcf_meta_info *mi, void *metaval, gfp_t gfp);
5148
int ife_alloc_meta_u16(struct tcf_meta_info *mi, void *metaval, gfp_t gfp);
5249
int ife_check_meta_u32(u32 metaval, struct tcf_meta_info *mi);

include/uapi/linux/Kbuild

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ header-y += if_tun.h
195195
header-y += if_tunnel.h
196196
header-y += if_vlan.h
197197
header-y += if_x25.h
198+
header-y += ife.h
198199
header-y += igmp.h
199200
header-y += ila.h
200201
header-y += in6.h

include/uapi/linux/ife.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#ifndef __UAPI_IFE_H
2+
#define __UAPI_IFE_H
3+
4+
#define IFE_METAHDRLEN 2
5+
6+
enum {
7+
IFE_META_SKBMARK = 1,
8+
IFE_META_HASHID,
9+
IFE_META_PRIO,
10+
IFE_META_QMAP,
11+
IFE_META_TCINDEX,
12+
__IFE_META_MAX
13+
};
14+
15+
/*Can be overridden at runtime by module option*/
16+
#define IFE_META_MAX (__IFE_META_MAX - 1)
17+
18+
#endif

include/uapi/linux/tc_act/tc_ife.h

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
#include <linux/types.h>
55
#include <linux/pkt_cls.h>
6+
#include <linux/ife.h>
67

78
#define TCA_ACT_IFE 25
89
/* Flag bits for now just encoding/decoding; mutually exclusive */
@@ -28,13 +29,4 @@ enum {
2829
};
2930
#define TCA_IFE_MAX (__TCA_IFE_MAX - 1)
3031

31-
#define IFE_META_SKBMARK 1
32-
#define IFE_META_HASHID 2
33-
#define IFE_META_PRIO 3
34-
#define IFE_META_QMAP 4
35-
#define IFE_META_TCINDEX 5
36-
/*Can be overridden at runtime by module option*/
37-
#define __IFE_META_MAX 6
38-
#define IFE_META_MAX (__IFE_META_MAX - 1)
39-
4032
#endif

net/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,7 @@ source "net/caif/Kconfig"
391391
source "net/ceph/Kconfig"
392392
source "net/nfc/Kconfig"
393393
source "net/psample/Kconfig"
394+
source "net/ife/Kconfig"
394395

395396
config LWTUNNEL
396397
bool "Network light weight tunnels"

net/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ obj-$(CONFIG_CEPH_LIB) += ceph/
7171
obj-$(CONFIG_BATMAN_ADV) += batman-adv/
7272
obj-$(CONFIG_NFC) += nfc/
7373
obj-$(CONFIG_PSAMPLE) += psample/
74+
obj-$(CONFIG_NET_IFE) += ife/
7475
obj-$(CONFIG_OPENVSWITCH) += openvswitch/
7576
obj-$(CONFIG_VSOCKETS) += vmw_vsock/
7677
obj-$(CONFIG_MPLS) += mpls/

net/ife/Kconfig

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#
2+
# IFE subsystem configuration
3+
#
4+
5+
menuconfig NET_IFE
6+
depends on NET
7+
tristate "Inter-FE based on IETF ForCES InterFE LFB"
8+
default n
9+
help
10+
Say Y here to add support of IFE encapsulation protocol
11+
For details refer to netdev01 paper:
12+
"Distributing Linux Traffic Control Classifier-Action Subsystem"
13+
Authors: Jamal Hadi Salim and Damascene M. Joachimpillai
14+
15+
To compile this support as a module, choose M here: the module will
16+
be called ife.

net/ife/Makefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#
2+
# Makefile for the IFE encapsulation protocol
3+
#
4+
5+
obj-$(CONFIG_NET_IFE) += ife.o

net/ife/ife.c

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
/*
2+
* net/ife/ife.c - Inter-FE protocol based on ForCES WG InterFE LFB
3+
* Copyright (c) 2015 Jamal Hadi Salim <[email protected]>
4+
* Copyright (c) 2017 Yotam Gigi <[email protected]>
5+
*
6+
* Refer to: draft-ietf-forces-interfelfb-03 and netdev01 paper:
7+
* "Distributing Linux Traffic Control Classifier-Action Subsystem"
8+
* Authors: Jamal Hadi Salim and Damascene M. Joachimpillai
9+
*
10+
* This program is free software; you can redistribute it and/or modify
11+
* it under the terms of the GNU General Public License as published by
12+
* the Free Software Foundation.
13+
*/
14+
15+
#include <linux/types.h>
16+
#include <linux/kernel.h>
17+
#include <linux/string.h>
18+
#include <linux/errno.h>
19+
#include <linux/skbuff.h>
20+
#include <linux/rtnetlink.h>
21+
#include <linux/module.h>
22+
#include <linux/init.h>
23+
#include <net/net_namespace.h>
24+
#include <net/netlink.h>
25+
#include <net/pkt_sched.h>
26+
#include <linux/etherdevice.h>
27+
#include <net/ife.h>
28+
29+
struct ifeheadr {
30+
__be16 metalen;
31+
u8 tlv_data[];
32+
};
33+
34+
void *ife_encode(struct sk_buff *skb, u16 metalen)
35+
{
36+
/* OUTERHDR:TOTMETALEN:{TLVHDR:Metadatum:TLVHDR..}:ORIGDATA
37+
* where ORIGDATA = original ethernet header ...
38+
*/
39+
int hdrm = metalen + IFE_METAHDRLEN;
40+
int total_push = hdrm + skb->dev->hard_header_len;
41+
struct ifeheadr *ifehdr;
42+
struct ethhdr *iethh; /* inner ether header */
43+
int skboff = 0;
44+
int err;
45+
46+
err = skb_cow_head(skb, total_push);
47+
if (unlikely(err))
48+
return NULL;
49+
50+
iethh = (struct ethhdr *) skb->data;
51+
52+
__skb_push(skb, total_push);
53+
memcpy(skb->data, iethh, skb->dev->hard_header_len);
54+
skb_reset_mac_header(skb);
55+
skboff += skb->dev->hard_header_len;
56+
57+
/* total metadata length */
58+
ifehdr = (struct ifeheadr *) (skb->data + skboff);
59+
metalen += IFE_METAHDRLEN;
60+
ifehdr->metalen = htons(metalen);
61+
62+
return ifehdr->tlv_data;
63+
}
64+
EXPORT_SYMBOL_GPL(ife_encode);
65+
66+
void *ife_decode(struct sk_buff *skb, u16 *metalen)
67+
{
68+
struct ifeheadr *ifehdr;
69+
int total_pull;
70+
u16 ifehdrln;
71+
72+
ifehdr = (struct ifeheadr *) (skb->data + skb->dev->hard_header_len);
73+
ifehdrln = ntohs(ifehdr->metalen);
74+
total_pull = skb->dev->hard_header_len + ifehdrln;
75+
76+
if (unlikely(ifehdrln < 2))
77+
return NULL;
78+
79+
if (unlikely(!pskb_may_pull(skb, total_pull)))
80+
return NULL;
81+
82+
skb_set_mac_header(skb, total_pull);
83+
__skb_pull(skb, total_pull);
84+
*metalen = ifehdrln - IFE_METAHDRLEN;
85+
86+
return &ifehdr->tlv_data;
87+
}
88+
EXPORT_SYMBOL_GPL(ife_decode);
89+
90+
struct meta_tlvhdr {
91+
__be16 type;
92+
__be16 len;
93+
};
94+
95+
/* Caller takes care of presenting data in network order
96+
*/
97+
void *ife_tlv_meta_decode(void *skbdata, u16 *attrtype, u16 *dlen, u16 *totlen)
98+
{
99+
struct meta_tlvhdr *tlv = (struct meta_tlvhdr *) skbdata;
100+
101+
*dlen = ntohs(tlv->len) - NLA_HDRLEN;
102+
*attrtype = ntohs(tlv->type);
103+
104+
if (totlen)
105+
*totlen = nla_total_size(*dlen);
106+
107+
return skbdata + sizeof(struct meta_tlvhdr);
108+
}
109+
EXPORT_SYMBOL_GPL(ife_tlv_meta_decode);
110+
111+
void *ife_tlv_meta_next(void *skbdata)
112+
{
113+
struct meta_tlvhdr *tlv = (struct meta_tlvhdr *) skbdata;
114+
u16 tlvlen = ntohs(tlv->len);
115+
116+
tlvlen = NLA_ALIGN(tlvlen);
117+
118+
return skbdata + tlvlen;
119+
}
120+
EXPORT_SYMBOL_GPL(ife_tlv_meta_next);
121+
122+
/* Caller takes care of presenting data in network order
123+
*/
124+
int ife_tlv_meta_encode(void *skbdata, u16 attrtype, u16 dlen, const void *dval)
125+
{
126+
__be32 *tlv = (__be32 *) (skbdata);
127+
u16 totlen = nla_total_size(dlen); /*alignment + hdr */
128+
char *dptr = (char *) tlv + NLA_HDRLEN;
129+
u32 htlv = attrtype << 16 | (dlen + NLA_HDRLEN);
130+
131+
*tlv = htonl(htlv);
132+
memset(dptr, 0, totlen - NLA_HDRLEN);
133+
memcpy(dptr, dval, dlen);
134+
135+
return totlen;
136+
}
137+
EXPORT_SYMBOL_GPL(ife_tlv_meta_encode);
138+
139+
MODULE_AUTHOR("Jamal Hadi Salim <[email protected]>");
140+
MODULE_AUTHOR("Yotam Gigi <[email protected]>");
141+
MODULE_DESCRIPTION("Inter-FE LFB action");
142+
MODULE_LICENSE("GPL");

net/sched/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -776,6 +776,7 @@ config NET_ACT_SKBMOD
776776
config NET_ACT_IFE
777777
tristate "Inter-FE action based on IETF ForCES InterFE LFB"
778778
depends on NET_CLS_ACT
779+
select NET_IFE
779780
---help---
780781
Say Y here to allow for sourcing and terminating metadata
781782
For details refer to netdev01 paper:

0 commit comments

Comments
 (0)