Skip to content

Commit 20cb84c

Browse files
authored
Workflow Improvements (#69)
This PR attempts to run the XDP program for 10 seconds when running the `run.yml` workflow instead of printing the help menu.
1 parent 3062ddd commit 20cb84c

File tree

3 files changed

+32
-22
lines changed

3 files changed

+32
-22
lines changed

.github/workflows/build.yml

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,14 @@
11
name: Build
22

33
on:
4-
push:
5-
branches: [ master ]
6-
pull_request:
7-
branches: [ master ]
8-
workflow_call:
4+
- push
95

106
jobs:
117
build:
128
runs-on: ubuntu-latest
139

1410
steps:
15-
- uses: actions/checkout@v2
11+
- uses: actions/checkout@v4
1612
with:
1713
submodules: recursive
1814
- name: Run apt update
@@ -34,7 +30,7 @@ jobs:
3430
- name: Install project
3531
run: sudo make install
3632
- name: Store build artifacts
37-
uses: actions/upload-artifact@master
33+
uses: actions/upload-artifact@v4
3834
with:
3935
name: build-output
40-
path: build/loader/xdpfw
36+
path: build/

.github/workflows/run.yml

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,17 @@
11
name: Run
22

33
on:
4-
push:
5-
branches: [ master ]
6-
pull_request:
7-
branches: [ master ]
4+
workflow_run:
5+
workflows: ["Build"]
6+
types: [completed]
87

98
jobs:
10-
reuse_build:
11-
uses: gamemann/XDP-Firewall/.github/workflows/build.yml@master
129
run:
13-
needs: reuse_build
1410
runs-on: ubuntu-latest
11+
1512
steps:
1613
- name: Download artifact from Build workflow
17-
uses: actions/download-artifact@master
18-
with:
19-
name: build-output
14+
uses: actions/download-artifact@v4
2015
- name: Run apt update
2116
run: sudo apt update
2217
- name: Install LibConfig
@@ -25,7 +20,15 @@ jobs:
2520
run: sudo apt install libelf-dev
2621
- name: List files
2722
run: ls -la
23+
- name: Create /etc/xdpfw directory.
24+
run: sudo mkdir -p /etc/xdpfw
25+
- name: Copy XDP program to /etc/xdpfw.
26+
run: sudo cp -f ./build-output/xdp/xdp_prog.o /etc/xdpfw
2827
- name: Add execute permissions to executable file
29-
run: sudo chmod +x ./xdpfw
30-
- name: Run XDP FW with help menu
31-
run: sudo ./xdpfw -h
28+
run: sudo chmod +x ./build-output/loader/xdpfw
29+
- name: Create basic config file.
30+
run: echo 'verbose = 5; filters = ( { enabled = true; log = true; action = 0; tcp_enabled = true; tcp_dport = 22; } );' > ./basic.conf
31+
- name: Retrieve default network interface
32+
run: echo "INTERFACE=$(ip route | awk '/default/ {print $5}')" >> $GITHUB_ENV
33+
- name: Run XDP FW for 10 seconds using basic config and default network interface.
34+
run: sudo ./build-output/loader/xdpfw -c ./basic.conf -t 10 -i ${{ env.INTERFACE }}

src/loader/utils/config.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,17 @@ int parse_cfg(config__t *cfg, const char* data, config_overrides_t* overrides)
273273
}
274274
}
275275
}
276+
else if (overrides && overrides->interface)
277+
{
278+
if (cfg->interfaces[0])
279+
{
280+
free(cfg->interfaces[0]);
281+
cfg->interfaces[0] = NULL;
282+
}
283+
284+
cfg->interfaces[0] = strdup(overrides->interface);
285+
cfg->interfaces_cnt = 1;
286+
}
276287

277288
// Pin BPF maps.
278289
int pin_maps;
@@ -1433,7 +1444,7 @@ void print_filter(filter_rule_cfg_t* filter, int idx)
14331444

14341445
// ICMP Options.
14351446
printf("\t\tICMP Options\n");
1436-
1447+
14371448
printf("\t\t\tICMP Enabled => %d\n", filter->icmp.enabled);
14381449
printf("\t\t\tICMP Code => %d\n", filter->icmp.code);
14391450
printf("\t\t\tICMP Type => %d\n", filter->icmp.type);

0 commit comments

Comments
 (0)