Skip to content

Commit cfdf64a

Browse files
skorpion17kuba-moo
authored andcommitted
seg6: add callbacks for customizing the creation/destruction of a behavior
We introduce two callbacks used for customizing the creation/destruction of a SRv6 behavior. Such callbacks are defined in the new struct seg6_local_lwtunnel_ops and hereafter we provide a brief description of them: - build_state(...): used for calling the custom constructor of the behavior during its initialization phase and after all the attributes have been parsed successfully; - destroy_state(...): used for calling the custom destructor of the behavior before it is completely destroyed. Signed-off-by: Andrea Mayer <[email protected]> Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 0a3021f commit cfdf64a

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

net/ipv6/seg6_local.c

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,13 @@
3333

3434
struct seg6_local_lwt;
3535

36+
/* callbacks used for customizing the creation and destruction of a behavior */
37+
struct seg6_local_lwtunnel_ops {
38+
int (*build_state)(struct seg6_local_lwt *slwt, const void *cfg,
39+
struct netlink_ext_ack *extack);
40+
void (*destroy_state)(struct seg6_local_lwt *slwt);
41+
};
42+
3643
struct seg6_action_desc {
3744
int action;
3845
unsigned long attrs;
@@ -53,6 +60,8 @@ struct seg6_action_desc {
5360

5461
int (*input)(struct sk_buff *skb, struct seg6_local_lwt *slwt);
5562
int static_headroom;
63+
64+
struct seg6_local_lwtunnel_ops slwt_ops;
5665
};
5766

5867
struct bpf_lwt_prog {
@@ -1055,6 +1064,38 @@ static int parse_nla_optional_attrs(struct nlattr **attrs,
10551064
return err;
10561065
}
10571066

1067+
/* call the custom constructor of the behavior during its initialization phase
1068+
* and after that all its attributes have been parsed successfully.
1069+
*/
1070+
static int
1071+
seg6_local_lwtunnel_build_state(struct seg6_local_lwt *slwt, const void *cfg,
1072+
struct netlink_ext_ack *extack)
1073+
{
1074+
struct seg6_action_desc *desc = slwt->desc;
1075+
struct seg6_local_lwtunnel_ops *ops;
1076+
1077+
ops = &desc->slwt_ops;
1078+
if (!ops->build_state)
1079+
return 0;
1080+
1081+
return ops->build_state(slwt, cfg, extack);
1082+
}
1083+
1084+
/* call the custom destructor of the behavior which is invoked before the
1085+
* tunnel is going to be destroyed.
1086+
*/
1087+
static void seg6_local_lwtunnel_destroy_state(struct seg6_local_lwt *slwt)
1088+
{
1089+
struct seg6_action_desc *desc = slwt->desc;
1090+
struct seg6_local_lwtunnel_ops *ops;
1091+
1092+
ops = &desc->slwt_ops;
1093+
if (!ops->destroy_state)
1094+
return;
1095+
1096+
ops->destroy_state(slwt);
1097+
}
1098+
10581099
static int parse_nla_action(struct nlattr **attrs, struct seg6_local_lwt *slwt)
10591100
{
10601101
struct seg6_action_param *param;
@@ -1154,6 +1195,10 @@ static int seg6_local_build_state(struct net *net, struct nlattr *nla,
11541195
if (err < 0)
11551196
goto out_free;
11561197

1198+
err = seg6_local_lwtunnel_build_state(slwt, cfg, extack);
1199+
if (err < 0)
1200+
goto out_destroy_attrs;
1201+
11571202
newts->type = LWTUNNEL_ENCAP_SEG6_LOCAL;
11581203
newts->flags = LWTUNNEL_STATE_INPUT_REDIRECT;
11591204
newts->headroom = slwt->headroom;
@@ -1162,6 +1207,8 @@ static int seg6_local_build_state(struct net *net, struct nlattr *nla,
11621207

11631208
return 0;
11641209

1210+
out_destroy_attrs:
1211+
destroy_attrs(slwt);
11651212
out_free:
11661213
kfree(newts);
11671214
return err;
@@ -1171,6 +1218,8 @@ static void seg6_local_destroy_state(struct lwtunnel_state *lwt)
11711218
{
11721219
struct seg6_local_lwt *slwt = seg6_local_lwtunnel(lwt);
11731220

1221+
seg6_local_lwtunnel_destroy_state(slwt);
1222+
11741223
destroy_attrs(slwt);
11751224

11761225
return;

0 commit comments

Comments
 (0)