Commit Graph

16 Commits

Author SHA1 Message Date
patryk4815 c96bb6363f
Fix Deadlock in `Flush` Function Due to ENOBUFS (#286)
* fix: resolve deadlock in `Flush` function when handling ENOBUFS error

* Simulate deadlock issue using reduced read/write buffers to verify the fix and ensure no regressions
2024-11-29 08:34:52 +01:00
_|+ ed578af895
Add WithSockOptions to modify netlink socket options (#277) 2024-09-23 17:19:43 +02:00
black-desk 6df7a82bbd
fix: correct error handling in receiveAckAware (#243)
Related: #242

After 7879d7ecf6, it seems that
any multi-message operation performed without CAP_SYS_ADMIN will
leads to forever block inside nftables.Conn.Flush.

For example:

```go
package main

import "github.com/google/nftables"

func main() {
	conn, err := nftables.New()
	if err != nil {
		panic(err)
	}

	t := conn.AddTable(&nftables.Table{})

	err = conn.AddSet(&nftables.Set{Table: t}, []nftables.SetElement{})
	if err != nil {
		panic(err)
	}

	conn.AddSet(&nftables.Set{Table: t}, []nftables.SetElement{})
	if err != nil {
		panic(err)
	}

	err = conn.Flush()
	if err != nil {
		panic(err)
	}

	return
}
```

That's because that although we send multiple messages on netlink
socket, kernel will only sends one permission error message as reply.

Signed-off-by: black-desk <me@black-desk.cn>
2023-10-21 22:11:55 +02:00
Ronak Jain 7879d7ecf6
Flush: fix error leak when flushing multiple messages (#239)
When you flush multiple messages/ops on a connection, and if flush fails
to apply, the netlink connection returns errors per command. Since we
are returning on noticing the first error, the rest of the errors are
buffered and leaks into the result of next flush.

This pull request invokes `conn.Receive()` * number of messages to drain
any buffered errors in the connection.
2023-10-01 23:06:11 +02:00
turekt 0d9bfa4d18
Fix overflow in Flush by using receiveAckAware and handling the overrun flag (#237)
Fixes https://github.com/google/nftables/issues/235
Added support for messages having overrun flag
Changed `conn.Receive` call to `receiveAckAware` in `Flush`
2023-09-23 17:08:35 +02:00
turekt 535f5eb8da
Fix incorrect netlink acknowledgement handling (#194)
fixes https://github.com/google/nftables/issues/175
2022-10-02 16:01:48 +02:00
Michael Stapelberg a346d51f53 Fetch an acknowledgement for each message that requested one
This fixes error handling when using lasting connections.

fixes #170
2022-06-11 23:33:46 +02:00
thediveo 3e042f75d7 refactor: pass table family when un/marshalling expr 2022-05-15 23:12:26 +02:00
TheDiveO eeaebcf552
add New constructor (with options functions, such as lasting connection)
* Close receiver for lasting netlink connections while defaulting to existing temporary netlink connection usage
* add unit test for New lasting connection, Close and correct default connection handling behavior
* refactor tests to use New constructor
* make Conn mutex un-exported (#159)

fixes issue #157
2022-05-09 13:25:29 +02:00
Matt Layher 611d399a5e
go.mod: use github.com/mdlayher/netlink@v1.4.2 (#136)
Signed-off-by: Matt Layher <mdlayher@gmail.com>
2021-12-09 23:08:14 +01:00
Serguei Bezverkhi 26bcabf490 disable lock when no namespace is needed (#95)
Signed-off-by: Serguei Bezverkhi <sbezverk@cisco.com>
2020-01-22 22:39:39 +01:00
Michael Stapelberg 2228941ec5 remove extra space 2019-12-22 11:45:11 +01:00
Serguei Bezverkhi 1f2240c488 Flush fix (#85)
Clear messages after netlink return error

Signed-off-by: Serguei Bezverkhi <sbezverk@cisco.com>
2019-12-22 11:44:25 +01:00
Serguei Bezverkhi f528bf5cc6 Replace %v with %w to wrap netlink error
Signed-off-by: Serguei Bezverkhi <sbezverk@cisco.com>
2019-12-20 11:51:15 -05:00
Serguei Bezverkhi 14f3137cde protect cc.messages from racing (#75)
Signed-off-by: Serguei Bezverkhi <sbezverk@cisco.com>
2019-11-14 16:22:42 +01:00
Ryan Whelan 7bac3e3135 Restructure code base into smaller files (#15)
* Restrcture code base into smaller files

* Package level doc string

* Move ExprsFromMsg back from expr sub-module

* gofmt
2019-05-03 23:54:09 +02:00