Skip to content

Commit 3ec5456

Browse files
authored
Merge pull request #135 from apernet/revert-pcap
Revert pcap
2 parents 5014523 + b51ea5f commit 3ec5456

File tree

7 files changed

+11
-184
lines changed

7 files changed

+11
-184
lines changed

.github/workflows/check.yaml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,6 @@ jobs:
2323
with:
2424
go-version: 'stable'
2525

26-
- name: Install pcap
27-
run: sudo apt install -y libpcap-dev
28-
2926
- run: go vet ./...
3027

3128
- name: staticcheck
@@ -47,7 +44,4 @@ jobs:
4744
with:
4845
go-version: 'stable'
4946

50-
- name: Install pcap
51-
run: sudo apt install -y libpcap-dev
52-
5347
- run: go test ./...

.github/workflows/release.yaml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,11 @@ jobs:
2424
with:
2525
go-version: "1.22"
2626

27-
- name: Install pcap
28-
run: sudo apt install -y libpcap-dev
29-
3027
- name: Build
3128
env:
3229
GOOS: ${{ matrix.goos }}
3330
GOARCH: ${{ matrix.goarch }}
31+
CGO_ENABLED: 0
3432
run: |
3533
mkdir -p build
3634
go build -o build/OpenGFW-${GOOS}-${GOARCH} -ldflags "-s -w" .

cmd/root.go

Lines changed: 8 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ var logger *zap.Logger
4343
// Flags
4444
var (
4545
cfgFile string
46-
pcapFile string
4746
logLevel string
4847
logFormat string
4948
)
@@ -119,7 +118,6 @@ func init() {
119118

120119
func initFlags() {
121120
rootCmd.PersistentFlags().StringVarP(&cfgFile, "config", "c", "", "config file")
122-
rootCmd.PersistentFlags().StringVarP(&pcapFile, "pcap", "p", "", "pcap file (optional)")
123121
rootCmd.PersistentFlags().StringVarP(&logLevel, "log-level", "l", envOrDefaultString(appLogLevelEnv, "info"), "log level")
124122
rootCmd.PersistentFlags().StringVarP(&logFormat, "log-format", "f", envOrDefaultString(appLogFormatEnv, "console"), "log format")
125123
}
@@ -169,7 +167,6 @@ type cliConfig struct {
169167
IO cliConfigIO `mapstructure:"io"`
170168
Workers cliConfigWorkers `mapstructure:"workers"`
171169
Ruleset cliConfigRuleset `mapstructure:"ruleset"`
172-
Replay cliConfigReplay `mapstructure:"replay"`
173170
}
174171

175172
type cliConfigIO struct {
@@ -180,10 +177,6 @@ type cliConfigIO struct {
180177
RST bool `mapstructure:"rst"`
181178
}
182179

183-
type cliConfigReplay struct {
184-
Realtime bool `mapstructure:"realtime"`
185-
}
186-
187180
type cliConfigWorkers struct {
188181
Count int `mapstructure:"count"`
189182
QueueSize int `mapstructure:"queueSize"`
@@ -204,30 +197,17 @@ func (c *cliConfig) fillLogger(config *engine.Config) error {
204197
}
205198

206199
func (c *cliConfig) fillIO(config *engine.Config) error {
207-
var ioImpl io.PacketIO
208-
var err error
209-
if pcapFile != "" {
210-
// Setup IO for pcap file replay
211-
logger.Info("replaying from pcap file", zap.String("pcap file", pcapFile))
212-
ioImpl, err = io.NewPcapPacketIO(io.PcapPacketIOConfig{
213-
PcapFile: pcapFile,
214-
Realtime: c.Replay.Realtime,
215-
})
216-
} else {
217-
// Setup IO for nfqueue
218-
ioImpl, err = io.NewNFQueuePacketIO(io.NFQueuePacketIOConfig{
219-
QueueSize: c.IO.QueueSize,
220-
ReadBuffer: c.IO.ReadBuffer,
221-
WriteBuffer: c.IO.WriteBuffer,
222-
Local: c.IO.Local,
223-
RST: c.IO.RST,
224-
})
225-
}
226-
200+
nfio, err := io.NewNFQueuePacketIO(io.NFQueuePacketIOConfig{
201+
QueueSize: c.IO.QueueSize,
202+
ReadBuffer: c.IO.ReadBuffer,
203+
WriteBuffer: c.IO.WriteBuffer,
204+
Local: c.IO.Local,
205+
RST: c.IO.RST,
206+
})
227207
if err != nil {
228208
return configError{Field: "io", Err: err}
229209
}
230-
config.IO = ioImpl
210+
config.IO = nfio
231211
return nil
232212
}
233213

engine/engine.go

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,17 +58,12 @@ func (e *engine) UpdateRuleset(r ruleset.Ruleset) error {
5858
}
5959

6060
func (e *engine) Run(ctx context.Context) error {
61-
workerCtx, workerCancel := context.WithCancel(ctx)
62-
defer workerCancel() // Stop workers
63-
64-
// Register IO shutdown
6561
ioCtx, ioCancel := context.WithCancel(ctx)
66-
e.io.SetCancelFunc(ioCancel)
67-
defer ioCancel() // Stop IO
62+
defer ioCancel() // Stop workers & IO
6863

6964
// Start workers
7065
for _, w := range e.workers {
71-
go w.Run(workerCtx)
66+
go w.Run(ioCtx)
7267
}
7368

7469
// Register IO callback
@@ -90,8 +85,6 @@ func (e *engine) Run(ctx context.Context) error {
9085
return err
9186
case <-ctx.Done():
9287
return nil
93-
case <-ioCtx.Done():
94-
return nil
9588
}
9689
}
9790

io/interface.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,6 @@ type PacketIO interface {
4848
ProtectedDialContext(ctx context.Context, network, address string) (net.Conn, error)
4949
// Close closes the packet IO.
5050
Close() error
51-
// SetCancelFunc gives packet IO access to context cancel function, enabling it to
52-
// trigger a shutdown
53-
SetCancelFunc(cancelFunc context.CancelFunc) error
5451
}
5552

5653
type ErrInvalidPacket struct {

io/nfqueue.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -281,11 +281,6 @@ func (n *nfqueuePacketIO) Close() error {
281281
return n.n.Close()
282282
}
283283

284-
// nfqueue IO does not issue shutdown
285-
func (n *nfqueuePacketIO) SetCancelFunc(cancelFunc context.CancelFunc) error {
286-
return nil
287-
}
288-
289284
func (n *nfqueuePacketIO) setupNft(local, rst, remove bool) error {
290285
rules, err := generateNftRules(local, rst)
291286
if err != nil {

io/pcap.go

Lines changed: 0 additions & 130 deletions
This file was deleted.

0 commit comments

Comments
 (0)