seg6_local.c (0a3021f1d4e553d9f3e7fc20e994b91af0687eb4) | seg6_local.c (cfdf64a03406351a9d6c1fe568a141a9a85d4710) |
---|---|
1// SPDX-License-Identifier: GPL-2.0-or-later 2/* 3 * SR-IPv6 implementation 4 * 5 * Authors: 6 * David Lebrun <david.lebrun@uclouvain.be> 7 * eBPF support: Mathieu Xhonneux <m.xhonneux@gmail.com> 8 */ --- 19 unchanged lines hidden (view full) --- 28#include <net/seg6_hmac.h> 29#endif 30#include <net/seg6_local.h> 31#include <linux/etherdevice.h> 32#include <linux/bpf.h> 33 34struct seg6_local_lwt; 35 | 1// SPDX-License-Identifier: GPL-2.0-or-later 2/* 3 * SR-IPv6 implementation 4 * 5 * Authors: 6 * David Lebrun <david.lebrun@uclouvain.be> 7 * eBPF support: Mathieu Xhonneux <m.xhonneux@gmail.com> 8 */ --- 19 unchanged lines hidden (view full) --- 28#include <net/seg6_hmac.h> 29#endif 30#include <net/seg6_local.h> 31#include <linux/etherdevice.h> 32#include <linux/bpf.h> 33 34struct seg6_local_lwt; 35 |
36/* callbacks used for customizing the creation and destruction of a behavior */ 37struct 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 |
|
36struct seg6_action_desc { 37 int action; 38 unsigned long attrs; 39 40 /* The optattrs field is used for specifying all the optional 41 * attributes supported by a specific behavior. 42 * It means that if one of these attributes is not provided in the 43 * netlink message during the behavior creation, no errors will be --- 4 unchanged lines hidden (view full) --- 48 * Every user MUST obey to this rule! If you set an attribute as 49 * required the same attribute CANNOT be set as optional and vice 50 * versa. 51 */ 52 unsigned long optattrs; 53 54 int (*input)(struct sk_buff *skb, struct seg6_local_lwt *slwt); 55 int static_headroom; | 43struct seg6_action_desc { 44 int action; 45 unsigned long attrs; 46 47 /* The optattrs field is used for specifying all the optional 48 * attributes supported by a specific behavior. 49 * It means that if one of these attributes is not provided in the 50 * netlink message during the behavior creation, no errors will be --- 4 unchanged lines hidden (view full) --- 55 * Every user MUST obey to this rule! If you set an attribute as 56 * required the same attribute CANNOT be set as optional and vice 57 * versa. 58 */ 59 unsigned long optattrs; 60 61 int (*input)(struct sk_buff *skb, struct seg6_local_lwt *slwt); 62 int static_headroom; |
63 64 struct seg6_local_lwtunnel_ops slwt_ops; |
|
56}; 57 58struct bpf_lwt_prog { 59 struct bpf_prog *prog; 60 char *name; 61}; 62 63struct seg6_local_lwt { --- 986 unchanged lines hidden (view full) --- 1050 return 0; 1051 1052parse_optattrs_err: 1053 __destroy_attrs(parsed_optattrs, i, slwt); 1054 1055 return err; 1056} 1057 | 65}; 66 67struct bpf_lwt_prog { 68 struct bpf_prog *prog; 69 char *name; 70}; 71 72struct seg6_local_lwt { --- 986 unchanged lines hidden (view full) --- 1059 return 0; 1060 1061parse_optattrs_err: 1062 __destroy_attrs(parsed_optattrs, i, slwt); 1063 1064 return err; 1065} 1066 |
1067/* call the custom constructor of the behavior during its initialization phase 1068 * and after that all its attributes have been parsed successfully. 1069 */ 1070static int 1071seg6_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 */ 1087static 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 |
|
1058static int parse_nla_action(struct nlattr **attrs, struct seg6_local_lwt *slwt) 1059{ 1060 struct seg6_action_param *param; 1061 struct seg6_action_desc *desc; 1062 unsigned long invalid_attrs; 1063 int i, err; 1064 1065 desc = __get_action_desc(slwt->action); --- 83 unchanged lines hidden (view full) --- 1149 1150 slwt = seg6_local_lwtunnel(newts); 1151 slwt->action = nla_get_u32(tb[SEG6_LOCAL_ACTION]); 1152 1153 err = parse_nla_action(tb, slwt); 1154 if (err < 0) 1155 goto out_free; 1156 | 1099static int parse_nla_action(struct nlattr **attrs, struct seg6_local_lwt *slwt) 1100{ 1101 struct seg6_action_param *param; 1102 struct seg6_action_desc *desc; 1103 unsigned long invalid_attrs; 1104 int i, err; 1105 1106 desc = __get_action_desc(slwt->action); --- 83 unchanged lines hidden (view full) --- 1190 1191 slwt = seg6_local_lwtunnel(newts); 1192 slwt->action = nla_get_u32(tb[SEG6_LOCAL_ACTION]); 1193 1194 err = parse_nla_action(tb, slwt); 1195 if (err < 0) 1196 goto out_free; 1197 |
1198 err = seg6_local_lwtunnel_build_state(slwt, cfg, extack); 1199 if (err < 0) 1200 goto out_destroy_attrs; 1201 |
|
1157 newts->type = LWTUNNEL_ENCAP_SEG6_LOCAL; 1158 newts->flags = LWTUNNEL_STATE_INPUT_REDIRECT; 1159 newts->headroom = slwt->headroom; 1160 1161 *ts = newts; 1162 1163 return 0; 1164 | 1202 newts->type = LWTUNNEL_ENCAP_SEG6_LOCAL; 1203 newts->flags = LWTUNNEL_STATE_INPUT_REDIRECT; 1204 newts->headroom = slwt->headroom; 1205 1206 *ts = newts; 1207 1208 return 0; 1209 |
1210out_destroy_attrs: 1211 destroy_attrs(slwt); |
|
1165out_free: 1166 kfree(newts); 1167 return err; 1168} 1169 1170static void seg6_local_destroy_state(struct lwtunnel_state *lwt) 1171{ 1172 struct seg6_local_lwt *slwt = seg6_local_lwtunnel(lwt); 1173 | 1212out_free: 1213 kfree(newts); 1214 return err; 1215} 1216 1217static void seg6_local_destroy_state(struct lwtunnel_state *lwt) 1218{ 1219 struct seg6_local_lwt *slwt = seg6_local_lwtunnel(lwt); 1220 |
1221 seg6_local_lwtunnel_destroy_state(slwt); 1222 |
|
1174 destroy_attrs(slwt); 1175 1176 return; 1177} 1178 1179static int seg6_local_fill_encap(struct sk_buff *skb, 1180 struct lwtunnel_state *lwt) 1181{ --- 109 unchanged lines hidden --- | 1223 destroy_attrs(slwt); 1224 1225 return; 1226} 1227 1228static int seg6_local_fill_encap(struct sk_buff *skb, 1229 struct lwtunnel_state *lwt) 1230{ --- 109 unchanged lines hidden --- |