mbuf_tags: use explicitly sized type for 'type' parameter
Functions manipulating mbuf tags are using an int type for passing the 'type' parameter, but the internal tag storage is using a 16bit integer to store it. This leads to the following code: t = m_tag_alloc(...,0xffffffff,...,...); m_tag_prepend(m, t); r = m_tag_locate(m ,...,0xffffffff, NULL); Returning r == NULL because m_tag_locate doesn't truncate the type parameter when doing the match. This is unexpected because the type of the 'type' parameter is int, and the caller doesn't need to know about the internal truncations. Fix this by making the 'type' parameter of type uint16_t in order to match the size of its internal storage and make it obvious to the caller the actual size of the parameter. While there also use uint uniformly replacing the existing u_int instances. Reviewed by: kp, donner, glebius Differential revision: https://reviews.freebsd.org/D33680
This commit is contained in:
parent
b99651c52f
commit
60e749da3c
@ -20,7 +20,7 @@
|
||||
.\"
|
||||
.\" $FreeBSD$
|
||||
.\"
|
||||
.Dd January 12, 2008
|
||||
.Dd December 28, 2021
|
||||
.Dt MBUF_TAGS 9
|
||||
.Os
|
||||
.Sh NAME
|
||||
@ -29,7 +29,7 @@
|
||||
.Sh SYNOPSIS
|
||||
.In sys/mbuf.h
|
||||
.Ft "struct m_tag *"
|
||||
.Fn m_tag_alloc "uint32_t cookie" "int type" "int len" "int wait"
|
||||
.Fn m_tag_alloc "uint32_t cookie" "uint16_t type" "int len" "int wait"
|
||||
.Ft "struct m_tag *"
|
||||
.Fn m_tag_copy "struct m_tag *t" "int how"
|
||||
.Ft int
|
||||
@ -41,17 +41,17 @@
|
||||
.Ft void
|
||||
.Fn m_tag_delete_nonpersistent "struct mbuf *m"
|
||||
.Ft "struct m_tag *"
|
||||
.Fn m_tag_find "struct mbuf *m" "int type" "struct m_tag *start"
|
||||
.Fn m_tag_find "struct mbuf *m" "uint16_t type" "struct m_tag *start"
|
||||
.Ft "struct m_tag *"
|
||||
.Fn m_tag_first "struct mbuf *m"
|
||||
.Ft void
|
||||
.Fn m_tag_free "struct m_tag *t"
|
||||
.Ft "struct m_tag *"
|
||||
.Fn m_tag_get "int type" "int len" "int wait"
|
||||
.Fn m_tag_get "uint16_t type" "int len" "int wait"
|
||||
.Ft void
|
||||
.Fn m_tag_init "struct mbuf *m"
|
||||
.Ft struct m_tag *
|
||||
.Fn m_tag_locate "struct mbuf *m" "uint32_t cookie" "int type" "struct m_tag *t"
|
||||
.Fn m_tag_locate "struct mbuf *m" "uint32_t cookie" "uint16_t type" "struct m_tag *t"
|
||||
.Ft "struct m_tag *"
|
||||
.Fn m_tag_next "struct mbuf *m" "struct m_tag *t"
|
||||
.Ft void
|
||||
|
@ -314,7 +314,7 @@ m_tag_free_default(struct m_tag *t)
|
||||
|
||||
/* Get a packet tag structure along with specified data following. */
|
||||
struct m_tag *
|
||||
m_tag_alloc(uint32_t cookie, int type, int len, int wait)
|
||||
m_tag_alloc(uint32_t cookie, uint16_t type, int len, int wait)
|
||||
{
|
||||
struct m_tag *t;
|
||||
|
||||
@ -376,7 +376,7 @@ m_tag_delete_nonpersistent(struct mbuf *m)
|
||||
|
||||
/* Find a tag, starting from a given position. */
|
||||
struct m_tag *
|
||||
m_tag_locate(struct mbuf *m, uint32_t cookie, int type, struct m_tag *t)
|
||||
m_tag_locate(struct mbuf *m, uint32_t cookie, uint16_t type, struct m_tag *t)
|
||||
{
|
||||
struct m_tag *p;
|
||||
|
||||
|
@ -1369,11 +1369,12 @@ extern bool mb_use_ext_pgs; /* Use ext_pgs for sendfile */
|
||||
/* Specific cookies and tags. */
|
||||
|
||||
/* Packet tag routines. */
|
||||
struct m_tag *m_tag_alloc(u_int32_t, int, int, int);
|
||||
struct m_tag *m_tag_alloc(uint32_t, uint16_t, int, int);
|
||||
void m_tag_delete(struct mbuf *, struct m_tag *);
|
||||
void m_tag_delete_chain(struct mbuf *, struct m_tag *);
|
||||
void m_tag_free_default(struct m_tag *);
|
||||
struct m_tag *m_tag_locate(struct mbuf *, u_int32_t, int, struct m_tag *);
|
||||
struct m_tag *m_tag_locate(struct mbuf *, uint32_t, uint16_t,
|
||||
struct m_tag *);
|
||||
struct m_tag *m_tag_copy(struct m_tag *, int);
|
||||
int m_tag_copy_chain(struct mbuf *, const struct mbuf *, int);
|
||||
void m_tag_delete_nonpersistent(struct mbuf *);
|
||||
@ -1395,7 +1396,7 @@ m_tag_init(struct mbuf *m)
|
||||
* XXX probably should be called m_tag_init, but that was already taken.
|
||||
*/
|
||||
static __inline void
|
||||
m_tag_setup(struct m_tag *t, u_int32_t cookie, int type, int len)
|
||||
m_tag_setup(struct m_tag *t, uint32_t cookie, uint16_t type, int len)
|
||||
{
|
||||
|
||||
t->m_tag_id = type;
|
||||
@ -1457,13 +1458,13 @@ m_tag_unlink(struct mbuf *m, struct m_tag *t)
|
||||
#define MTAG_ABI_COMPAT 0 /* compatibility ABI */
|
||||
|
||||
static __inline struct m_tag *
|
||||
m_tag_get(int type, int length, int wait)
|
||||
m_tag_get(uint16_t type, int length, int wait)
|
||||
{
|
||||
return (m_tag_alloc(MTAG_ABI_COMPAT, type, length, wait));
|
||||
}
|
||||
|
||||
static __inline struct m_tag *
|
||||
m_tag_find(struct mbuf *m, int type, struct m_tag *start)
|
||||
m_tag_find(struct mbuf *m, uint16_t type, struct m_tag *start)
|
||||
{
|
||||
return (SLIST_EMPTY(&m->m_pkthdr.tags) ? (struct m_tag *)NULL :
|
||||
m_tag_locate(m, MTAG_ABI_COMPAT, type, start));
|
||||
|
Loading…
Reference in New Issue
Block a user