diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml
index 7802aec..d95a193 100644
--- a/.github/workflows/release.yml
+++ b/.github/workflows/release.yml
@@ -37,3 +37,9 @@ jobs:
VSIX_FILE=$(ls *.vsix | head -n 1)
echo "Uploading $VSIX_FILE to release ${{ github.event.release.tag_name }}"
gh release upload "${{ github.event.release.tag_name }}" "$VSIX_FILE" --clobber
+
+ - name: Publish to VSCode Marketplace
+ env:
+ VSCE_PAT: ${{ secrets.VSCE_PAT }}
+ run: |
+ vsce publish -p "$VSCE_PAT"
\ No newline at end of file
diff --git a/README.md b/README.md
index 90abeb2..6afcd9a 100644
--- a/README.md
+++ b/README.md
@@ -1,29 +1,35 @@
# eBPF Snippets
-Code-snippets for developing eBPF programs
+Code snippets for developing **eBPF** programs.
-
+
+
+
+---
## Installation
+1. Go to the latest [release](https://github.com/h0x0er/ebpf-snippets/releases) and download the `.vsix` file.
-1. GOTO latest [release](https://github.com/h0x0er/ebpf-snippets/releases) and download the `vsix` file.
+
+
+
-
+1. In VS Code:
+ 1. Press `Ctrl + Shift + P`
+ 2. Type **Install from VSIX** and press **Enter**
+ 3. Select the downloaded `.vsix` file
-2. In vscode, hit `ctrl+shift+p`,
- 1. type `install from vsix` and hit-enter, then
- 2. choose the downloaded `vsix file`
+
+
+
-
+**Enjoy 🙂**
-**Enjoy :)**
+---
+## References
-
-### References
-
-- https://docs.ebpf.io/
-- https://docs.kernel.org/bpf/libbpf/program_types.html
-
+- [eBPF Documentation](https://docs.ebpf.io/)
+- [Linux Kernel BPF Program Types](https://docs.kernel.org/bpf/libbpf/program_types.html)
diff --git a/package.json b/package.json
index d81e9ec..f3ce8c5 100644
--- a/package.json
+++ b/package.json
@@ -14,7 +14,7 @@
"engines": {
"vscode": "^1.0.0"
},
- "publisher": "h0x0er",
+ "publisher": "jatin-experiment-01",
"categories": [
"Snippets"
],
@@ -31,6 +31,10 @@
{
"language": "c",
"path": "./snippets/progs-tracing.code-snippets"
+ },
+ {
+ "language": "c",
+ "path": "./snippets/progs-network.code-snippets"
}
]
},
diff --git a/snippets/maps.code-snippets b/snippets/maps.code-snippets
index dc8f96e..c9f2cbf 100644
--- a/snippets/maps.code-snippets
+++ b/snippets/maps.code-snippets
@@ -24,12 +24,14 @@
"prefix": "bpf-map-generic",
"body": [
"struct {",
- "\t__uint(type, ${1|BPF_MAP_TYPE_HASH,BPF_MAP_TYPE_PERCPU_ARRAY,BPF_MAP_TYPE_LPM_TRIE,BPF_MAP_TYPE_ARRAY,BPF_MAP_TYPE_PERCPU_ARRAY,BPF_MAP_TYPE_LRU_HASH,BPF_MAP_TYPE_LRU_PERCPU_HASH,BPF_MAP_TYPE_LPM_TRIE,BPF_MAP_TYPE_BLOOM_FILTER,BPF_MAP_TYPE_ARENA|});",
+ "\t__uint(type, ${1|BPF_MAP_TYPE_HASH,BPF_MAP_TYPE_PERCPU_HASH,BPF_MAP_TYPE_LPM_TRIE,BPF_MAP_TYPE_ARRAY,BPF_MAP_TYPE_PERCPU_ARRAY,BPF_MAP_TYPE_LRU_HASH,BPF_MAP_TYPE_LRU_PERCPU_HASH,BPF_MAP_TYPE_LPM_TRIE,BPF_MAP_TYPE_BLOOM_FILTER,BPF_MAP_TYPE_ARENA,BPF_MAP_TYPE_QUEUE,BPF_MAP_TYPE_STACK,BPF_MAP_TYPE_PERF_EVENT_ARRAY|});",
"\t__type(key, ${2:u64});",
- "\t__type(value, ${3:u8});",
- "\t__uint(max_entries, ${4:100});",
+ "\t__uint(key_size, ${3:sizeof(u64)}); // remove if not needed",
+ "\t__type(value, ${4:u8});",
+ "\t__uint(value_size, ${5:sizeof(u64)}); // remove if not needed",
+ "\t__uint(max_entries, ${6:100});",
"\t__array(values, struct my_value); // remove if not needed",
- "\t__uint(map_flags, ${5|BPF_F_NO_PREALLOC,BPF_F_NUMA_NODE,BPF_F_RDONLY,BPF_F_RDONLY_PROG,BPF_F_WRONLY_PROG|}); // remove if not needed",
+ "\t__uint(map_flags, ${7|BPF_F_NO_PREALLOC,BPF_F_NUMA_NODE,BPF_F_RDONLY,BPF_F_RDONLY_PROG,BPF_F_WRONLY_PROG|}); // remove if not needed",
"} ${0:my_map_name} SEC(\".maps\");"
]
},
@@ -39,10 +41,10 @@
"body": [
"struct {",
"\t__uint(type, ${1|BPF_MAP_TYPE_ARRAY_OF_MAPS,BPF_MAP_TYPE_HASH_OF_MAPS|});",
- "\t__uint(max_entries, ${4:100});",
- "\t__type(key, ${2:u64});",
- "\t__array(values, struct my_value);",
- "} ${5:my_map_name} SEC(\".maps\");"
+ "\t__uint(max_entries, ${2:100});",
+ "\t__type(key, ${3:u64});",
+ "\t__array(values, ${4:struct my_value});",
+ "} ${0:my_map_name} SEC(\".maps\");"
]
},
"create bpf prog_array map": {
diff --git a/snippets/progs-cgroup.code-snippets b/snippets/progs-cgroup.code-snippets
index eb3ea8a..cd0ce9f 100644
--- a/snippets/progs-cgroup.code-snippets
+++ b/snippets/progs-cgroup.code-snippets
@@ -53,4 +53,13 @@
"int handle_sysctl(struct bpf_sysctl *ctx){ return 1; }"
]
},
+ "create cgroup sock-ops prog": {
+ "scope": "c",
+ "description": "",
+ "prefix": "bpf-prog-cgroup-sock-ops",
+ "body": [
+ "SEC(\"sockops\")",
+ "int handle_sockops(struct bpf_sock_ops *ctx){ return 1; }"
+ ]
+ },
}
\ No newline at end of file
diff --git a/snippets/progs-network.code-snippets b/snippets/progs-network.code-snippets
new file mode 100644
index 0000000..b83468d
--- /dev/null
+++ b/snippets/progs-network.code-snippets
@@ -0,0 +1,74 @@
+{
+ "create classifier prog (tc/tcx)": {
+ "scope": "c",
+ "description": "Refer: https://docs.ebpf.io/linux/program-type/BPF_PROG_TYPE_SCHED_CLS/",
+ "prefix": "bpf-prog-tc",
+ "body": [
+ "SEC(\"${1|tc/egress,tc/ingress,tcx/egress,tcx/ingress|}\")",
+ "int handle_${1/[\\/]/_/}(struct __sk_buff *skb){ return -1; }"
+ ]
+ },
+ "create xdp prog": {
+ "scope": "c",
+ "description": "Refer: https://docs.ebpf.io/linux/program-type/BPF_PROG_TYPE_XDP/#usage",
+ "prefix": "bpf-prog-xdp",
+ "body": [
+ "SEC(\"xdp\")",
+ "int handle_xdp(struct xdp_md *ctx){ return XDP_PASS; }"
+ ]
+ },
+ "create sk_skb prog": {
+ "scope": "c",
+ "description": "Refer: https://docs.ebpf.io/linux/program-type/BPF_PROG_TYPE_SK_SKB/",
+ "prefix": "bpf-prog-sk-skb",
+ "body": [
+ "SEC(\"sk_skb/${1|stream_parser,stream_verdict|}\")",
+ "int handle_$1(struct __sk_buff *skb){ return 1; }"
+ ]
+ },
+ "create sk_msg prog": {
+ "scope": "c",
+ "description": "Refer: https://docs.ebpf.io/linux/program-type/BPF_PROG_TYPE_SK_MSG/",
+ "prefix": "bpf-prog-sk-msg",
+ "body": [
+ "SEC(\"sk_msg\")",
+ "int handle_skmsg(struct sk_msg_md *msg){ return SK_PASS; }"
+ ]
+ },
+ "create sk_lookup prog": {
+ "scope": "c",
+ "description": "Refer: https://docs.ebpf.io/linux/program-type/BPF_PROG_TYPE_SK_LOOKUP/",
+ "prefix": "bpf-prog-sk-lookup",
+ "body": [
+ "SEC(\"sk_lookup\")",
+ "int handle_sklookup(struct bpf_sk_lookup *ctx){ return SK_PASS; }"
+ ]
+ },
+ "create sk_reuseport prog": {
+ "scope": "c",
+ "description": "Refer: https://docs.ebpf.io/linux/program-type/BPF_PROG_TYPE_SK_REUSEPORT/#usage",
+ "prefix": "bpf-prog-sk-reuseport",
+ "body": [
+ "SEC(\"${1|sk_reuseport,sk_reuseport/migrate|}\")",
+ "int handle_sk_reuseport(struct sk_reuseport_md *ctx){ return SK_PASS; }"
+ ]
+ },
+ "create flow_dissector prog": {
+ "scope": "c",
+ "description": "Refer: https://docs.ebpf.io/linux/program-type/BPF_PROG_TYPE_FLOW_DISSECTOR/#context",
+ "prefix": "bpf-prog-flow-dissector",
+ "body": [
+ "SEC(\"flow_dissector\")",
+ "int handle_dissector(struct __sk_buff *skb){ return BPF_OK; }"
+ ]
+ },
+ "create netfliter prog": {
+ "scope": "c",
+ "description": "Refer: https://docs.ebpf.io/linux/program-type/BPF_PROG_TYPE_NETFILTER/",
+ "prefix": "bpf-prog-netfilter",
+ "body": [
+ "SEC(\"netfilter\")",
+ "int do_netfilter(struct bpf_nf_ctx *ctx){ return NF_ACCEPT; }"
+ ]
+ },
+}
\ No newline at end of file