aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/bpf/syscall.c
diff options
context:
space:
mode:
authorJohn Fastabend <john.fastabend@gmail.com>2017-08-28 10:10:04 -0400
committerDavid S. Miller <davem@davemloft.net>2017-08-28 14:13:21 -0400
commit464bc0fd6273d518aee79fbd37211dd9bc35d863 (patch)
tree32280f0588583c50f6712de2ad0e3af886dcaadd /kernel/bpf/syscall.c
parent901c5d2fbfcdc5d1d49a7a835b9ce9be5eee6393 (diff)
bpf: convert sockmap field attach_bpf_fd2 to type
In the initial sockmap API we provided strparser and verdict programs using a single attach command by extending the attach API with a the attach_bpf_fd2 field. However, if we add other programs in the future we will be adding a field for every new possible type, attach_bpf_fd(3,4,..). This seems a bit clumsy for an API. So lets push the programs using two new type fields. BPF_SK_SKB_STREAM_PARSER BPF_SK_SKB_STREAM_VERDICT This has the advantage of having a readable name and can easily be extended in the future. Updates to samples and sockmap included here also generalize tests slightly to support upcoming patch for multiple map support. Signed-off-by: John Fastabend <john.fastabend@gmail.com> Fixes: 174a79ff9515 ("bpf: sockmap with sk redirect support") Suggested-by: Alexei Starovoitov <ast@kernel.org> Acked-by: Alexei Starovoitov <ast@kernel.org> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'kernel/bpf/syscall.c')
-rw-r--r--kernel/bpf/syscall.c38
1 files changed, 11 insertions, 27 deletions
diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c
index 9378f3ba2cbf..021a05d9d800 100644
--- a/kernel/bpf/syscall.c
+++ b/kernel/bpf/syscall.c
@@ -1093,12 +1093,12 @@ static int bpf_obj_get(const union bpf_attr *attr)
1093 1093
1094#ifdef CONFIG_CGROUP_BPF 1094#ifdef CONFIG_CGROUP_BPF
1095 1095
1096#define BPF_PROG_ATTACH_LAST_FIELD attach_bpf_fd2 1096#define BPF_PROG_ATTACH_LAST_FIELD attach_flags
1097 1097
1098static int sockmap_get_from_fd(const union bpf_attr *attr, int ptype) 1098static int sockmap_get_from_fd(const union bpf_attr *attr)
1099{ 1099{
1100 struct bpf_prog *prog1, *prog2;
1101 int ufd = attr->target_fd; 1100 int ufd = attr->target_fd;
1101 struct bpf_prog *prog;
1102 struct bpf_map *map; 1102 struct bpf_map *map;
1103 struct fd f; 1103 struct fd f;
1104 int err; 1104 int err;
@@ -1108,29 +1108,16 @@ static int sockmap_get_from_fd(const union bpf_attr *attr, int ptype)
1108 if (IS_ERR(map)) 1108 if (IS_ERR(map))
1109 return PTR_ERR(map); 1109 return PTR_ERR(map);
1110 1110
1111 if (!map->ops->map_attach) { 1111 prog = bpf_prog_get_type(attr->attach_bpf_fd, BPF_PROG_TYPE_SK_SKB);
1112 fdput(f); 1112 if (IS_ERR(prog)) {
1113 return -EOPNOTSUPP;
1114 }
1115
1116 prog1 = bpf_prog_get_type(attr->attach_bpf_fd, ptype);
1117 if (IS_ERR(prog1)) {
1118 fdput(f); 1113 fdput(f);
1119 return PTR_ERR(prog1); 1114 return PTR_ERR(prog);
1120 }
1121
1122 prog2 = bpf_prog_get_type(attr->attach_bpf_fd2, ptype);
1123 if (IS_ERR(prog2)) {
1124 fdput(f);
1125 bpf_prog_put(prog1);
1126 return PTR_ERR(prog2);
1127 } 1115 }
1128 1116
1129 err = map->ops->map_attach(map, prog1, prog2); 1117 err = sock_map_attach_prog(map, prog, attr->attach_type);
1130 if (err) { 1118 if (err) {
1131 fdput(f); 1119 fdput(f);
1132 bpf_prog_put(prog1); 1120 bpf_prog_put(prog);
1133 bpf_prog_put(prog2);
1134 return err; 1121 return err;
1135 } 1122 }
1136 1123
@@ -1165,16 +1152,13 @@ static int bpf_prog_attach(const union bpf_attr *attr)
1165 case BPF_CGROUP_SOCK_OPS: 1152 case BPF_CGROUP_SOCK_OPS:
1166 ptype = BPF_PROG_TYPE_SOCK_OPS; 1153 ptype = BPF_PROG_TYPE_SOCK_OPS;
1167 break; 1154 break;
1168 case BPF_CGROUP_SMAP_INGRESS: 1155 case BPF_SK_SKB_STREAM_PARSER:
1169 ptype = BPF_PROG_TYPE_SK_SKB; 1156 case BPF_SK_SKB_STREAM_VERDICT:
1170 break; 1157 return sockmap_get_from_fd(attr);
1171 default: 1158 default:
1172 return -EINVAL; 1159 return -EINVAL;
1173 } 1160 }
1174 1161
1175 if (attr->attach_type == BPF_CGROUP_SMAP_INGRESS)
1176 return sockmap_get_from_fd(attr, ptype);
1177
1178 prog = bpf_prog_get_type(attr->attach_bpf_fd, ptype); 1162 prog = bpf_prog_get_type(attr->attach_bpf_fd, ptype);
1179 if (IS_ERR(prog)) 1163 if (IS_ERR(prog))
1180 return PTR_ERR(prog); 1164 return PTR_ERR(prog);