git: if_tun: Fix error handling, input validation and minor issues
Aaron LI
aly at crater.dragonflybsd.org
Sun Oct 11 07:02:28 PDT 2026
commit 1405477991eed41c116c6126a14150283c0dbae8
Author: Aaron LI <aly at aaronly.me>
Date: Sun Oct 11 13:14:01 2026 +0800
if_tun: Fix error handling, input validation and minor issues
* tunclone(): Handle unit allocation failure; rollback changes if
if_clone_create() fails.
* tuncreate(): Handle if_alloc() failure to not leak the 'sc'.
* tun_clone_create(): Simplify bitmap unit conflict, which is an
out-of-sync and shouldn't happen; rollback changes if tuncreate()
fails.
* tunifioctl(): Use ksnprintf() to avoid possible ifs->ascii overrun.
* tunifoutput_serialized():
- Drop packets if the interface is not up, like FreeBSD.
- Handle short or fragmented packets from BPF writes.
- Fix ifq_classify() by moving it after the BPF handling.
- Add IFNET_STAT_INC() for obytes.
* tunioctl():
- Validate MTU range, similar to the check done in if.c.
- Clear the IFF_MULTICAST bit.
* tunwrite(): Simplify and optimize mbuf chain building by using
m_uiomove(), which uses mbuf clusters to save allocations.
* Refresh the man page.
Some fixes/updates are derived from the FreeBSD code.
Assisted-by: Claude Sonnet 5
Summary of changes:
share/man/man4/tun.4 | 184 +++++++++++++++++++++++++++------------------------
sys/net/tun/if_tun.c | 153 +++++++++++++++++++++++++-----------------
2 files changed, 190 insertions(+), 147 deletions(-)
http://gitweb.dragonflybsd.org/dragonfly.git/commitdiff/1405477991eed41c116c6126a14150283c0dbae8
--
DragonFly BSD source repository
More information about the Commits
mailing list