From a8babb6361f498ad4ec130129442557417062299 Mon Sep 17 00:00:00 2001 From: yar Date: Wed, 31 Aug 2005 11:36:50 +0000 Subject: [PATCH] Use VLAN_TAG_VALUE() not only to read a dot1q tag value from an m_tag, but also to set it. This reduces complex code duplication and improves its readability. Alas, we shouldn't rename the macro to VLAN_TAG_LVALUE() globally because that would cause pain for kernel module port maintainers and vendors using FreeBSD as their codebase. Added a clarifying comment instead. Discussed with: ru, glebius X-MFC-After: 6.0-RELEASE (MFC is good just to reduce the diff) --- sys/net/if_vlan.c | 2 +- sys/net/if_vlan_var.h | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/sys/net/if_vlan.c b/sys/net/if_vlan.c index 5a8fafe6d42..758800acadf 100644 --- a/sys/net/if_vlan.c +++ b/sys/net/if_vlan.c @@ -502,7 +502,7 @@ vlan_start(struct ifnet *ifp) m_freem(m); continue; } - *(u_int*)(mtag + 1) = ifv->ifv_tag; + VLAN_TAG_VALUE(mtag) = ifv->ifv_tag; m_tag_prepend(m, mtag); m->m_flags |= M_VLANTAG; } else { diff --git a/sys/net/if_vlan_var.h b/sys/net/if_vlan_var.h index 11cbf7b20fc..c55d5d1ec55 100644 --- a/sys/net/if_vlan_var.h +++ b/sys/net/if_vlan_var.h @@ -96,6 +96,12 @@ struct vlanreq { #define MTAG_VLAN 1035328035 #define MTAG_VLAN_TAG 0 /* tag of VLAN interface */ +/* + * This macro must expand to a lvalue so that it can be used + * to set a tag with a simple assignment. + */ +#define VLAN_TAG_VALUE(_mt) (*(u_int *)((_mt) + 1)) + #define VLAN_INPUT_TAG(_ifp, _m, _t, _errcase) do { \ struct m_tag *mtag; \ mtag = m_tag_alloc(MTAG_VLAN, MTAG_VLAN_TAG, \ @@ -105,7 +111,7 @@ struct vlanreq { m_freem(_m); \ _errcase; \ } \ - *(u_int *)(mtag+1) = (_t); \ + VLAN_TAG_VALUE(mtag) = (_t); \ m_tag_prepend((_m), mtag); \ (_m)->m_flags |= M_VLANTAG; \ } while (0) @@ -113,7 +119,6 @@ struct vlanreq { #define VLAN_OUTPUT_TAG(_ifp, _m) \ ((_m)->m_flags & M_VLANTAG ? \ m_tag_locate((_m), MTAG_VLAN, MTAG_VLAN_TAG, NULL) : NULL) -#define VLAN_TAG_VALUE(_mt) (*(u_int *)((_mt)+1)) #endif /* _KERNEL */ #endif /* _NET_IF_VLAN_VAR_H_ */ -- 2.45.2