-
Notifications
You must be signed in to change notification settings - Fork 2.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ng_pipe: Various improvements #1181
Conversation
Signed-off-by: Martin Vahlensieck <git@academicsolutions.ch>
This is the behavior described in the man page. Signed-off-by: Martin Vahlensieck <git@academicsolutions.ch>
Authorized ci |
sys/netgraph/ng_pipe.c
Outdated
@@ -771,7 +771,7 @@ pipe_dequeue(struct hookinfo *hinfo, struct timeval *now) { | |||
* the original packet... | |||
*/ | |||
if (hinfo->cfg.duplicate && | |||
random() % 100 <= hinfo->cfg.duplicate) { | |||
arc4random() % 100 <= hinfo->cfg.duplicate) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why arc4random() instead of prng32() or prng32_bounded()? The former is a cryptographic PRNG, which doesn't look to be what you want.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed, as well as the other random(9)
replacement.
sys/netgraph/ng_pipe.c
Outdated
@@ -814,7 +828,7 @@ pipe_dequeue(struct hookinfo *hinfo, struct timeval *now) { | |||
/* Randomly discard the frame, according to BER setting */ | |||
if (hinfo->cfg.ber) { | |||
oldrand = rand; | |||
rand = random(); | |||
rand = prng32() & 0x7fffffff; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This calls for prng32_bounded() as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
sys/netgraph/ng_pipe.c
Outdated
@@ -976,7 +998,7 @@ ngp_modevent(module_t mod, int type, void *unused) | |||
sizeof (struct ngp_fifo)), NULL, NULL, NULL, NULL, | |||
UMA_ALIGN_PTR, 0); | |||
if (ngp_zone == NULL) | |||
panic("ng_pipe: couldn't allocate descriptor zone"); | |||
error = ENOMEM; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This check can simply be removed: uma_zcreate() never fails.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They aren't different, that code doesn't need to check either. It's just cargo-culting.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed
@@ -658,7 +660,8 @@ ngp_rcvdata(hook_p hook, item_p item) | |||
break; | |||
if (ngp_f == NULL) { | |||
ngp_f = uma_zalloc(ngp_zone, M_NOWAIT); | |||
KASSERT(ngp_h != NULL, ("ngp_h zalloc failed (2)")); | |||
if (ngp_f == NULL) | |||
return (ENOMEM); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here you're leaking ngp_h (and maybe other things).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch!
Signed-off-by: Martin Vahlensieck <git@academicsolutions.ch>
Signed-off-by: Martin Vahlensieck <git@academicsolutions.ch>
This looks good to me. Maybe @glebius could comment on the functional change (destroying the node when hooks are removed)? |
Given this behavior is documented and also it is typical for many other nodes, I believe the patch does the right thing. |
Landed, thanks. |
Signed-off-by: Martin Vahlensieck <git@academicsolutions.ch> Reviewed by: markj MFC after: 2 weeks Pull Request: #1181
This is the behavior described in the man page. Signed-off-by: Martin Vahlensieck <git@academicsolutions.ch> Discussed with: glebius Reviewed by: markj MFC after: 2 weeks Pull Request: #1181
Signed-off-by: Martin Vahlensieck <git@academicsolutions.ch> MFC after: 2 weeks Reviewed by: markj Pull Request: #1181
Signed-off-by: Martin Vahlensieck <git@academicsolutions.ch> Reviewed by: markj MFC after: 2 weeks Pull Request: #1181
Thank you for your help! |
Various small improvements to
ng_pipe(4)
:random(9)
witharc4random(9)