Skip to content

PR: HeaderAction::Modify should not panic on missing metadata #241 - #242

Merged
rzezeski merged 1 commit into
masterfrom
opte-241-unwrap-panic-and-kstats
Sep 9, 2022
Merged

rzezeski merged 1 commit into
masterfrom
opte-241-unwrap-panic-and-kstats

Conversation

@rzezeski

@rzezeski rzezeski commented Aug 26, 2022 •

Copy link
Copy Markdown
Contributor
HeaderAction::Modify should not panic on missing metadata (#241)

The main thrust of this commit is to fix #241 by allowing a
`HeaderAction` to return an error result. Some other stuff came along
for the ride.

- add some basic kstats support (#23)

  With yet another possible runtime error I thought it was high time
  we had some kstats support. There is already good SDT support in
  OPTE, but if you're not running DTrace when an error occurs, you're
  not going to know it happened. Having kstats allows us to track
  historical failures/errors and provide a clue as to where to look
  when debugging live.

  While trying to implement kstats I realized that I need to change
  the locking scheme in OPTE. OPTE was my first real Rust project; a
  packet transformation engine running Rust in the illumos kernel --
  it was a lot to take on for a first Rust project. I brought a lot of
  my previous knowledge to bear from working on the illumos networking
  stack, particularly the mac module. From this past knowledge my
  initial architecture relied on a lot of Arc + fine-grained locks
  inside of the engine, as this is the structure I was used to seeing
  inside illumos.

  When trying to implement kstats I realized that I would have to wrap
  a mutex around a group of named kstats...and that just felt weird
  compared to how we do it in most illumos network drivers.
  Furthermore, the fine-grained locking I had in place wasn't actually
  completely correct, and relied on some hard-to-understand comments
  and non-idiomatic Rust code. Then I had the thought that I should
  really be treating an individual Port more like a Tx/Rx ring that you
  would find in a network driver, where the entire ring is locked
  during processing. In this sense the entire Port should be wrapped
  in a mutex, knowing that any state changed inside that Port is
  atomic in respect to a given packet (or chain of packets). If and
  when this proves to be a limiting factor, you can then start
  breaking things out at a higher level, like having each Port broken
  out into concurrent streams for different protocol types: like TCP,
  UDP, and Other. If that becomes a bottleneck you could then possibly
  break each protocol out further into rings, assuming you could find
  a way to consistently hash flows to their appropriate ring.
  Furthermore, the happy path for an active flow is always hitting the
  UFT. There may be ways to structure the UFT such that it can be
  queried without a mutex, perhaps with some type of scheme that uses
  asynchronous updates of a persistent (read functional) data structure
  plus atomic pointer swaps. The point being, there are higher-level
  ways to reduce contention than the fine grained locking scheme I had
  used up to this point.

- Renamed `ModActionArg` to `ModifyActionArg`, because I kept
  confusing `Mod` with "module" in my head, and I wrote this damn
  code!

- Renamed `HT` to `HdrTransform` to make it a bit more obvious what it
  refers to.

@rzezeski rzezeski mentioned this pull request Aug 27, 2022
@rzezeski

Copy link
Copy Markdown
Contributor Author

Once #246 lands I'll rebase this and the checks should pass again.

@rzezeski
rzezeski force-pushed the opte-241-unwrap-panic-and-kstats branch from dfb6144 to 8b42d0a Compare August 30, 2022 23:34
@rzezeski

Copy link
Copy Markdown
Contributor Author

Still need to go through some TODOs.

@rzezeski
rzezeski force-pushed the opte-241-unwrap-panic-and-kstats branch 2 times, most recently from d906c9d to 85e70ef Compare August 31, 2022 20:54
@rzezeski

rzezeski commented Aug 31, 2022 •

Copy link
Copy Markdown
Contributor Author

I verified this patch prevents the panic described in #231 by creating an instance with no external IP and trying to ping the address 1.1.1.1. Now, instead of panicking, the out_process_err stat is incremented and the port process SDT probe shows an error being returned.

pz@kalm:~$ kstat -p xde::opte0:
xde:0:opte0:class       net
xde:0:opte0:crtime      1004.604303417
xde:0:opte0:in_bypass   0
xde:0:opte0:in_drop     14
xde:0:opte0:in_drop_layer       14
xde:0:opte0:in_drop_tcp_closed  0
xde:0:opte0:in_drop_tcp_err     0
xde:0:opte0:in_hairpin  0
xde:0:opte0:in_modified 14
xde:0:opte0:in_process_err      0
xde:0:opte0:out_bypass  0
xde:0:opte0:out_drop    0
xde:0:opte0:out_drop_layer      0
xde:0:opte0:out_drop_tcp_closed 0
xde:0:opte0:out_drop_tcp_err    0
xde:0:opte0:out_hairpin 3
xde:0:opte0:out_modified        0
xde:0:opte0:out_process_err     14
xde:0:opte0:snaptime    1252.759800969

rpz@kalm:~/opte-dtrace$ pfexec ./opte-trace opte-port-process.d 
NAME         DIR EPOCH    FLOW                                        LEN   RESULT
opte0        out 3        ICMP,172.30.0.5:0,1.1.1.1:0                 98    ERROR: Layer(HeaderTransform(MissingHeader("inner ULP")))
opte0        out 3        ICMP,172.30.0.5:0,1.1.1.1:0                 98    ERROR: Layer(HeaderTransform(MissingHeader("inner ULP")))
opte0        out 3        ICMP,172.30.0.5:0,1.1.1.1:0                 98    ERROR: Layer(HeaderTransform(MissingHeader("inner ULP")))
^C
opte0        out 3        ICMP,172.30.0.5:0,1.1.1.1:0                 98    ERROR: Layer(HeaderTransform(MissingHeader("inner ULP")))

@rzezeski
rzezeski requested a review from bnaecker August 31, 2022 21:30

@bnaecker bnaecker left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like a lot of great cleanup: the kstats, locking simplification, and the check for the missing ULP. Thanks!

Comment thread illumos-sys-hdrs/src/lib.rs Resolved
Comment thread kstat-macro/src/lib.rs Resolved
Comment thread kstat-macro/src/lib.rs Resolved
Comment thread opte/src/ddi/kstat.rs Resolved
Comment thread opte/src/ddi/kstat.rs Resolved
Comment thread opte/src/engine/nat.rs Resolved
Comment thread opte/src/engine/snat.rs Resolved
Comment thread opte/src/engine/sync.rs Resolved
Comment thread oxide-vpc/src/engine/dhcp4.rs Resolved
Comment thread opte/src/engine/port.rs Resolved
@rzezeski

rzezeski commented Sep 9, 2022

Copy link
Copy Markdown
Contributor Author

Okay @bnaecker, I think I addressed all your concerns. When you get a chance give it a look and see if I missed anything.

@rzezeski
rzezeski requested a review from bnaecker September 9, 2022 17:22

@bnaecker bnaecker left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, this looks good to me. Thanks for going through all that, the comments especially were very helpful.

The main thrust of this commit is to fix #241 by allowing a
`HeaderAction` to return an error result. Some other stuff came along
for the ride.

- add some basic kstats support (#23)

  With yet another possible runtime error I thought it was high time
  we had some kstats support. There is already good SDT support in
  OPTE, but if you're not running DTrace when an error occurs, you're
  not going to know it happened. Having kstats allows us to track
  historical failures/errors and provide a clue as to where to look
  when debugging live.

  While trying to implement kstats I realized that I need to change
  the locking scheme in OPTE. OPTE was my first real Rust project; a
  packet transformation engine running Rust in the illumos kernel --
  it was a lot to take on for a first Rust project. I brought a lot of
  my previous knowledge to bear from working on the illumos networking
  stack, particularly the mac module. From this past knowledge my
  initial architecture relied on a lot of Arc + fine-grained locks
  inside of the engine, as this is the structure I was used to seeing
  inside illumos.

  When trying to implement kstats I realized that I would have to wrap
  a mutex around a group of named kstats...and that just felt weird
  compared to how we do it in most illumos network drivers.
  Furthermore, the fine-grained locking I had in place wasn't actually
  completely correct, and relied on some hard-to-understand comments
  and non-idiomatic Rust code. Then I had the thought that I should
  really be treating an individual Port more like a Tx/Rx ring that you
  would find in a network driver, where the entire ring is locked
  during processing. In this sense the entire Port should be wrapped
  in a mutex, knowing that any state changed inside that Port is
  atomic in respect to a given packet (or chain of packets). If and
  when this proves to be a limiting factor, you can then start
  breaking things out at a higher level, like having each Port broken
  out into concurrent streams for different protocol types: like TCP,
  UDP, and Other. If that becomes a bottleneck you could then possibly
  break each protocol out further into rings, assuming you could find
  a way to consistently hash flows to their appropriate ring.
  Furthermore, the happy path for an active flow is always hitting the
  UFT. There may be ways to structure the UFT such that it can be
  queried without a mutex, perhaps with some type of scheme that uses
  asynchronous updates of a persistent (read functional) data structure
  plus atomic pointer swaps. The point being, there are higher-level
  ways to reduce contention than the fine grained locking scheme I had
  used up to this point.

- Renamed `ModActionArg` to `ModifyActionArg`, because I kept
  confusing `Mod` with "module" in my head, and I wrote this damn
  code!

- Renamed `HT` to `HdrTransform` to make it a bit more obvious what it
  refers to.
@rzezeski
rzezeski force-pushed the opte-241-unwrap-panic-and-kstats branch from f416a5a to 971340d Compare September 9, 2022 21:40
@rzezeski
rzezeski merged commit 971340d into master Sep 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants