Skip to content

Commit b8e177a

Browse files
committed
route: cls: flower: extend API
The following API has been added: - rtnl_flower_set_src_port_range - rtnl_flower_get_src_port_range - rtnl_flower_set_dst_port_range - rtnl_flower_get_dst_port_range
1 parent c71f865 commit b8e177a

File tree

4 files changed

+138
-0
lines changed

4 files changed

+138
-0
lines changed

include/netlink-private/types.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -643,6 +643,10 @@ struct rtnl_flower
643643
uint8_t cf_ip_proto;
644644
uint8_t cf_ip_ttl;
645645
uint8_t cf_ip_ttl_mask;
646+
uint16_t cf_src_port_min;
647+
uint16_t cf_src_port_max;
648+
uint16_t cf_dst_port_min;
649+
uint16_t cf_dst_port_max;
646650
};
647651

648652
struct rtnl_cgroup

include/netlink/route/cls/flower.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,11 @@ extern int rtnl_flower_append_action(struct rtnl_cls *, struct rtnl_act *);
6060
extern int rtnl_flower_del_action(struct rtnl_cls *, struct rtnl_act *);
6161
extern struct rtnl_act* rtnl_flower_get_action(struct rtnl_cls *);
6262

63+
extern int rtnl_flower_set_src_port_range(struct rtnl_cls *cls, uint16_t min, uint16_t max);
64+
extern int rtnl_flower_get_src_port_range(struct rtnl_cls *cls, uint16_t *min, uint16_t *max);
65+
extern int rtnl_flower_set_dst_port_range(struct rtnl_cls *cls, uint16_t min, uint16_t max);
66+
extern int rtnl_flower_get_dst_port_range(struct rtnl_cls *cls, uint16_t *min, uint16_t *max);
67+
6368
#ifdef __cplusplus
6469
}
6570
#endif

lib/route/cls/flower.c

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@
3434
#define FLOWER_ATTR_IP_PROTO (1 << 16)
3535
#define FLOWER_ATTR_IP_TTL (1 << 17)
3636
#define FLOWER_ATTR_IP_TTL_MASK (1 << 18)
37+
#define FLOWER_ATTR_SRC_PORT_MIN (1 << 19)
38+
#define FLOWER_ATTR_SRC_PORT_MAX (1 << 20)
39+
#define FLOWER_ATTR_DST_PORT_MIN (1 << 21)
40+
#define FLOWER_ATTR_DST_PORT_MAX (1 << 22)
41+
3742
/** @endcond */
3843

3944
#define FLOWER_DSCP_MAX 0xe0
@@ -172,6 +177,26 @@ static int flower_msg_parser(struct rtnl_tc *tc, void *data)
172177
f->cf_mask |= FLOWER_ATTR_IP_PROTO;
173178
}
174179

180+
if (tb[TCA_FLOWER_KEY_PORT_SRC_MIN]) {
181+
f->cf_src_port_min = nla_get_u16(tb[TCA_FLOWER_KEY_PORT_SRC_MIN]);
182+
f->cf_mask |= FLOWER_ATTR_SRC_PORT_MIN;
183+
}
184+
185+
if (tb[TCA_FLOWER_KEY_PORT_SRC_MAX]) {
186+
f->cf_src_port_max = nla_get_u16(tb[TCA_FLOWER_KEY_PORT_SRC_MAX]);
187+
f->cf_mask |= FLOWER_ATTR_SRC_PORT_MAX;
188+
}
189+
190+
if (tb[TCA_FLOWER_KEY_PORT_DST_MIN]) {
191+
f->cf_dst_port_min = nla_get_u16(tb[TCA_FLOWER_KEY_PORT_DST_MIN]);
192+
f->cf_mask |= FLOWER_ATTR_DST_PORT_MIN;
193+
}
194+
195+
if (tb[TCA_FLOWER_KEY_PORT_DST_MAX]) {
196+
f->cf_dst_port_max = nla_get_u16(tb[TCA_FLOWER_KEY_PORT_DST_MAX]);
197+
f->cf_mask |= FLOWER_ATTR_DST_PORT_MAX;
198+
}
199+
175200
return 0;
176201
}
177202

@@ -245,6 +270,18 @@ static int flower_msg_fill(struct rtnl_tc *tc, void *data, struct nl_msg *msg)
245270
if (f->cf_mask & FLOWER_ATTR_IP_PROTO)
246271
NLA_PUT_U8(msg, TCA_FLOWER_KEY_IP_PROTO, f->cf_ip_proto);
247272

273+
if (f->cf_mask & FLOWER_ATTR_SRC_PORT_MIN)
274+
NLA_PUT_U16(msg, TCA_FLOWER_KEY_PORT_SRC_MIN, f->cf_src_port_min);
275+
276+
if (f->cf_mask & FLOWER_ATTR_SRC_PORT_MAX)
277+
NLA_PUT_U16(msg, TCA_FLOWER_KEY_PORT_SRC_MAX, f->cf_src_port_max);
278+
279+
if (f->cf_mask & FLOWER_ATTR_DST_PORT_MIN)
280+
NLA_PUT_U16(msg, TCA_FLOWER_KEY_PORT_DST_MIN, f->cf_dst_port_min);
281+
282+
if (f->cf_mask & FLOWER_ATTR_DST_PORT_MIN)
283+
NLA_PUT_U16(msg, TCA_FLOWER_KEY_PORT_DST_MAX, f->cf_dst_port_max);
284+
248285
return 0;
249286

250287
nla_put_failure:
@@ -1045,6 +1082,94 @@ int rtnl_flower_get_flags(struct rtnl_cls *cls, int *flags)
10451082
return 0;
10461083
}
10471084

1085+
int rtnl_flower_set_src_port_range(struct rtnl_cls *cls, uint16_t min, uint16_t max)
1086+
{
1087+
struct rtnl_flower *f = rtnl_tc_data(TC_CAST(cls));
1088+
1089+
if (!f)
1090+
return -NLE_NOMEM;
1091+
1092+
if (min) {
1093+
f->cf_src_port_min = htons(min);
1094+
f->cf_mask |= FLOWER_ATTR_SRC_PORT_MIN;
1095+
}
1096+
1097+
if (max) {
1098+
f->cf_src_port_max = htons(max);
1099+
f->cf_mask |= FLOWER_ATTR_SRC_PORT_MAX;
1100+
}
1101+
1102+
return 0;
1103+
}
1104+
1105+
int rtnl_flower_set_dst_port_range(struct rtnl_cls *cls, uint16_t min, uint16_t max)
1106+
{
1107+
struct rtnl_flower *f = rtnl_tc_data(TC_CAST(cls));
1108+
1109+
if (!f)
1110+
return -NLE_NOMEM;
1111+
1112+
if (min) {
1113+
f->cf_dst_port_min = htons(min);
1114+
f->cf_mask |= FLOWER_ATTR_DST_PORT_MIN;
1115+
}
1116+
1117+
if (max) {
1118+
f->cf_dst_port_max = htons(max);
1119+
f->cf_mask |= FLOWER_ATTR_DST_PORT_MAX;
1120+
}
1121+
1122+
return 0;
1123+
}
1124+
1125+
int rtnl_flower_get_src_port_range(struct rtnl_cls *cls, uint16_t *min, uint16_t *max)
1126+
{
1127+
struct rtnl_flower *f = rtnl_tc_data_peek(TC_CAST(cls));
1128+
1129+
if (!f)
1130+
return -NLE_INVAL;
1131+
1132+
if (min) {
1133+
if (f->cf_mask & FLOWER_ATTR_SRC_PORT_MIN)
1134+
*min = ntohs(f->cf_src_port_min);
1135+
else
1136+
*min = 0;
1137+
}
1138+
1139+
if (max) {
1140+
if (f->cf_mask & FLOWER_ATTR_SRC_PORT_MAX)
1141+
*max = ntohs(f->cf_src_port_max);
1142+
else
1143+
*max = 0;
1144+
}
1145+
1146+
return 0;
1147+
}
1148+
1149+
int rtnl_flower_get_dst_port_range(struct rtnl_cls *cls, uint16_t *min, uint16_t *max)
1150+
{
1151+
struct rtnl_flower *f = rtnl_tc_data_peek(TC_CAST(cls));
1152+
1153+
if (!f)
1154+
return -NLE_INVAL;
1155+
1156+
if (min) {
1157+
if (f->cf_mask & FLOWER_ATTR_DST_PORT_MIN)
1158+
*min = ntohs(f->cf_dst_port_min);
1159+
else
1160+
*min = 0;
1161+
}
1162+
1163+
if (max) {
1164+
if (f->cf_mask & FLOWER_ATTR_DST_PORT_MAX)
1165+
*max = ntohs(f->cf_dst_port_max);
1166+
else
1167+
*max = 0;
1168+
}
1169+
1170+
return 0;
1171+
}
1172+
10481173
/** @} */
10491174

10501175
static struct rtnl_tc_ops flower_ops = {

libnl-route-3.sym

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1365,4 +1365,8 @@ global:
13651365
rtnl_flower_set_ip_ttl;
13661366
rtnl_flower_get_ip_ttl;
13671367
rtnl_link_unset_carrier_request_flag;
1368+
rtnl_flower_set_src_port_range;
1369+
rtnl_flower_get_src_port_range;
1370+
rtnl_flower_set_dst_port_range;
1371+
rtnl_flower_get_dst_port_range;
13681372
} libnl_3_6;

0 commit comments

Comments
 (0)