Const'ify variables to make it clear we're not writing to the mbuf data.
Reviewed by: julian, brian MFC after: 1 week
This commit is contained in:
parent
7b9f235f4c
commit
816b834f14
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=97897
@ -556,7 +556,7 @@ static int
|
||||
nglmi_rcvdata(hook_p hook, item_p item)
|
||||
{
|
||||
sc_p sc = NG_NODE_PRIVATE(NG_HOOK_NODE(hook));
|
||||
u_char *data;
|
||||
const u_char *data;
|
||||
unsigned short dlci;
|
||||
u_short packetlen;
|
||||
int resptype_seen = 0;
|
||||
@ -584,7 +584,7 @@ nglmi_rcvdata(hook_p hook, item_p item)
|
||||
return (0);
|
||||
|
||||
/* pass the first 4 bytes (already checked in the nglmi_checkdata()) */
|
||||
data = mtod(m, u_char *);
|
||||
data = mtod(m, const u_char *);
|
||||
STEPBY(4);
|
||||
|
||||
/* Now check if there is a 'locking shift'. This is only seen in
|
||||
@ -741,7 +741,7 @@ static int
|
||||
nglmi_checkdata(hook_p hook, struct mbuf *m)
|
||||
{
|
||||
sc_p sc = NG_NODE_PRIVATE(NG_HOOK_NODE(hook));
|
||||
u_char *data;
|
||||
const u_char *data;
|
||||
u_short packetlen;
|
||||
unsigned short dlci;
|
||||
u_char type;
|
||||
@ -751,7 +751,7 @@ nglmi_checkdata(hook_p hook, struct mbuf *m)
|
||||
int highest_dlci = 0;
|
||||
|
||||
packetlen = m->m_hdr.mh_len;
|
||||
data = mtod(m, u_char *);
|
||||
data = mtod(m, const u_char *);
|
||||
if (*data != 0x03) {
|
||||
log(LOG_WARNING, "nglmi: unexpected value in LMI(%d)\n", 1);
|
||||
goto reject;
|
||||
@ -994,7 +994,7 @@ nglmi_checkdata(hook_p hook, struct mbuf *m)
|
||||
int i, j, k, pos;
|
||||
char buf[100];
|
||||
int loc;
|
||||
u_char *bp = mtod(m, u_char *);
|
||||
const u_char *bp = mtod(m, const u_char *);
|
||||
|
||||
k = i = 0;
|
||||
loc = (m->m_hdr.mh_len - packetlen);
|
||||
@ -1021,7 +1021,7 @@ nglmi_checkdata(hook_p hook, struct mbuf *m)
|
||||
int i, j, k, pos;
|
||||
char buf[100];
|
||||
int loc;
|
||||
u_char *bp = mtod(m, u_char *);
|
||||
const u_char *bp = mtod(m, const u_char *);
|
||||
|
||||
k = i = 0;
|
||||
loc = (m->m_hdr.mh_len - packetlen);
|
||||
|
@ -202,7 +202,7 @@ struct sess_neg {
|
||||
struct callout_handle timeout_handle; /* see timeout(9) */
|
||||
u_int timeout; /* 0,1,2,4,8,16 etc. seconds */
|
||||
u_int numtags;
|
||||
struct pppoe_tag *tags[NUMTAGS];
|
||||
const struct pppoe_tag *tags[NUMTAGS];
|
||||
u_int service_len;
|
||||
u_int ac_name_len;
|
||||
|
||||
@ -277,7 +277,8 @@ union uniq {
|
||||
static void pppoe_start(sessp sp);
|
||||
static void sendpacket(sessp sp);
|
||||
static void pppoe_ticker(void *arg);
|
||||
static struct pppoe_tag* scan_tags(sessp sp, struct pppoe_hdr* ph);
|
||||
static const struct pppoe_tag *scan_tags(sessp sp,
|
||||
const struct pppoe_hdr* ph);
|
||||
static int pppoe_send_event(sessp sp, enum cmd cmdid);
|
||||
|
||||
/*************************************************************************
|
||||
@ -328,10 +329,11 @@ AAA
|
||||
/*
|
||||
* Return the location where the next tag can be put
|
||||
*/
|
||||
static __inline struct pppoe_tag*
|
||||
next_tag(struct pppoe_hdr* ph)
|
||||
static __inline const struct pppoe_tag*
|
||||
next_tag(const struct pppoe_hdr* ph)
|
||||
{
|
||||
return (struct pppoe_tag*)(((char*)&ph->tag[0]) + ntohs(ph->length));
|
||||
return (const struct pppoe_tag*)(((const char*)&ph->tag[0])
|
||||
+ ntohs(ph->length));
|
||||
}
|
||||
|
||||
/*
|
||||
@ -339,28 +341,28 @@ next_tag(struct pppoe_hdr* ph)
|
||||
* Don't trust any length the other end says.
|
||||
* but assume we already sanity checked ph->length.
|
||||
*/
|
||||
static struct pppoe_tag*
|
||||
get_tag(struct pppoe_hdr* ph, u_int16_t idx)
|
||||
static const struct pppoe_tag*
|
||||
get_tag(const struct pppoe_hdr* ph, u_int16_t idx)
|
||||
{
|
||||
char *end = (char *)next_tag(ph);
|
||||
char *ptn;
|
||||
struct pppoe_tag *pt = &ph->tag[0];
|
||||
const char *const end = (const char *)next_tag(ph);
|
||||
const char *ptn;
|
||||
const struct pppoe_tag *pt = &ph->tag[0];
|
||||
/*
|
||||
* Keep processing tags while a tag header will still fit.
|
||||
*/
|
||||
AAA
|
||||
while((char*)(pt + 1) <= end) {
|
||||
while((const char*)(pt + 1) <= end) {
|
||||
/*
|
||||
* If the tag data would go past the end of the packet, abort.
|
||||
*/
|
||||
ptn = (((char *)(pt + 1)) + ntohs(pt->tag_len));
|
||||
ptn = (((const char *)(pt + 1)) + ntohs(pt->tag_len));
|
||||
if(ptn > end)
|
||||
return NULL;
|
||||
|
||||
if(pt->tag_type == idx)
|
||||
return pt;
|
||||
|
||||
pt = (struct pppoe_tag*)ptn;
|
||||
pt = (const struct pppoe_tag*)ptn;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
@ -383,7 +385,7 @@ AAA
|
||||
}
|
||||
|
||||
static void
|
||||
insert_tag(sessp sp, struct pppoe_tag *tp)
|
||||
insert_tag(sessp sp, const struct pppoe_tag *tp)
|
||||
{
|
||||
int i;
|
||||
negp neg;
|
||||
@ -412,7 +414,7 @@ AAA
|
||||
static void
|
||||
make_packet(sessp sp) {
|
||||
struct pppoe_full_hdr *wh = &sp->neg->pkt->pkt_header;
|
||||
struct pppoe_tag **tag;
|
||||
const struct pppoe_tag **tag;
|
||||
char *dp;
|
||||
int count;
|
||||
int tlen;
|
||||
@ -432,7 +434,7 @@ AAA
|
||||
sp->neg->numtags = count;
|
||||
break; /* XXX chop off what's too long */
|
||||
}
|
||||
bcopy((char *)*tag, (char *)dp, tlen);
|
||||
bcopy(*tag, (char *)dp, tlen);
|
||||
length += tlen;
|
||||
dp += tlen;
|
||||
}
|
||||
@ -456,7 +458,7 @@ AAA
|
||||
#define NG_MATCH_ANY 2
|
||||
|
||||
static hook_p
|
||||
pppoe_match_svc(node_p node, char *svc_name, int svc_len, int match)
|
||||
pppoe_match_svc(node_p node, const char *svc_name, int svc_len, int match)
|
||||
{
|
||||
sessp sp = NULL;
|
||||
negp neg = NULL;
|
||||
@ -503,7 +505,7 @@ AAA
|
||||
* Routine to find a particular session that matches an incoming packet *
|
||||
**************************************************************************/
|
||||
static hook_p
|
||||
pppoe_findsession(node_p node, struct pppoe_full_hdr *wh)
|
||||
pppoe_findsession(node_p node, const struct pppoe_full_hdr *wh)
|
||||
{
|
||||
sessp sp = NULL;
|
||||
hook_p hook = NULL;
|
||||
@ -534,7 +536,7 @@ AAA
|
||||
}
|
||||
|
||||
static hook_p
|
||||
pppoe_finduniq(node_p node, struct pppoe_tag *tag)
|
||||
pppoe_finduniq(node_p node, const struct pppoe_tag *tag)
|
||||
{
|
||||
hook_p hook = NULL;
|
||||
priv_p privp = NG_NODE_PRIVATE(node);
|
||||
@ -889,7 +891,7 @@ AAA
|
||||
}
|
||||
|
||||
static int
|
||||
send_acname(sessp sp, struct pppoe_tag *tag)
|
||||
send_acname(sessp sp, const struct pppoe_tag *tag)
|
||||
{
|
||||
int error;
|
||||
struct ng_mesg *msg;
|
||||
@ -936,13 +938,13 @@ ng_pppoe_rcvdata(hook_p hook, item_p item)
|
||||
node_p node = NG_HOOK_NODE(hook);
|
||||
const priv_p privp = NG_NODE_PRIVATE(node);
|
||||
sessp sp = NG_HOOK_PRIVATE(hook);
|
||||
struct pppoe_full_hdr *wh;
|
||||
struct pppoe_hdr *ph;
|
||||
const struct pppoe_full_hdr *wh;
|
||||
const struct pppoe_hdr *ph;
|
||||
int error = 0;
|
||||
u_int16_t session;
|
||||
u_int16_t length;
|
||||
u_int8_t code;
|
||||
struct pppoe_tag *utag = NULL, *tag = NULL;
|
||||
const struct pppoe_tag *utag = NULL, *tag = NULL;
|
||||
hook_p sendhook;
|
||||
struct {
|
||||
struct pppoe_tag hdr;
|
||||
@ -1681,21 +1683,21 @@ AAA
|
||||
* output packet. Don't do any tags that have been handled in the main
|
||||
* state machine.
|
||||
*/
|
||||
static struct pppoe_tag*
|
||||
scan_tags(sessp sp, struct pppoe_hdr* ph)
|
||||
static const struct pppoe_tag*
|
||||
scan_tags(sessp sp, const struct pppoe_hdr* ph)
|
||||
{
|
||||
char *end = (char *)next_tag(ph);
|
||||
char *ptn;
|
||||
struct pppoe_tag *pt = &ph->tag[0];
|
||||
const char *const end = (const char *)next_tag(ph);
|
||||
const char *ptn;
|
||||
const struct pppoe_tag *pt = &ph->tag[0];
|
||||
/*
|
||||
* Keep processing tags while a tag header will still fit.
|
||||
*/
|
||||
AAA
|
||||
while((char*)(pt + 1) <= end) {
|
||||
while((const char*)(pt + 1) <= end) {
|
||||
/*
|
||||
* If the tag data would go past the end of the packet, abort.
|
||||
*/
|
||||
ptn = (((char *)(pt + 1)) + ntohs(pt->tag_len));
|
||||
ptn = (((const char *)(pt + 1)) + ntohs(pt->tag_len));
|
||||
if(ptn > end)
|
||||
return NULL;
|
||||
|
||||
@ -1715,7 +1717,7 @@ AAA
|
||||
case PTT_GEN_ERR:
|
||||
break;
|
||||
}
|
||||
pt = (struct pppoe_tag*)ptn;
|
||||
pt = (const struct pppoe_tag*)ptn;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
@ -569,8 +569,8 @@ ng_pptpgre_recv(node_p node, item_p item)
|
||||
{
|
||||
const priv_p priv = NG_NODE_PRIVATE(node);
|
||||
int iphlen, grelen, extralen;
|
||||
struct greheader *gre;
|
||||
struct ip *ip;
|
||||
const struct greheader *gre;
|
||||
const struct ip *ip;
|
||||
int error = 0;
|
||||
struct mbuf *m;
|
||||
|
||||
@ -595,7 +595,7 @@ ng_pptpgre_recv(node_p node, item_p item)
|
||||
NG_FREE_ITEM(item);
|
||||
return (ENOBUFS);
|
||||
}
|
||||
ip = mtod(m, struct ip *);
|
||||
ip = mtod(m, const struct ip *);
|
||||
iphlen = ip->ip_hl << 2;
|
||||
if (m->m_len < iphlen + sizeof(*gre)) {
|
||||
if ((m = m_pullup(m, iphlen + sizeof(*gre))) == NULL) {
|
||||
@ -603,9 +603,9 @@ ng_pptpgre_recv(node_p node, item_p item)
|
||||
NG_FREE_ITEM(item);
|
||||
return (ENOBUFS);
|
||||
}
|
||||
ip = mtod(m, struct ip *);
|
||||
ip = mtod(m, const struct ip *);
|
||||
}
|
||||
gre = (struct greheader *)((u_char *)ip + iphlen);
|
||||
gre = (const struct greheader *)((const u_char *)ip + iphlen);
|
||||
grelen = sizeof(*gre) + sizeof(u_int32_t) * (gre->hasSeq + gre->hasAck);
|
||||
if (m->m_pkthdr.len < iphlen + grelen) {
|
||||
priv->stats.recvRunts++;
|
||||
@ -617,8 +617,8 @@ ng_pptpgre_recv(node_p node, item_p item)
|
||||
NG_FREE_ITEM(item);
|
||||
return (ENOBUFS);
|
||||
}
|
||||
ip = mtod(m, struct ip *);
|
||||
gre = (struct greheader *)((u_char *)ip + iphlen);
|
||||
ip = mtod(m, const struct ip *);
|
||||
gre = (const struct greheader *)((const u_char *)ip + iphlen);
|
||||
}
|
||||
|
||||
/* Sanity check packet length and GRE header bits */
|
||||
@ -628,7 +628,8 @@ ng_pptpgre_recv(node_p node, item_p item)
|
||||
priv->stats.recvBadGRE++;
|
||||
goto bad;
|
||||
}
|
||||
if ((ntohl(*((u_int32_t *)gre)) & PPTP_INIT_MASK) != PPTP_INIT_VALUE) {
|
||||
if ((ntohl(*((const u_int32_t *)gre)) & PPTP_INIT_MASK)
|
||||
!= PPTP_INIT_VALUE) {
|
||||
priv->stats.recvBadGRE++;
|
||||
goto bad;
|
||||
}
|
||||
|
@ -215,12 +215,13 @@ ng_rfc1490_rcvdata(hook_p hook, item_p item)
|
||||
|
||||
NGI_GET_M(item, m);
|
||||
if (hook == priv->downlink) {
|
||||
u_char *start, *ptr;
|
||||
const u_char *start;
|
||||
const u_char *ptr;
|
||||
|
||||
if (!m || (m->m_len < MAX_ENCAPS_HDR
|
||||
&& !(m = m_pullup(m, MAX_ENCAPS_HDR))))
|
||||
ERROUT(ENOBUFS);
|
||||
ptr = start = mtod(m, u_char *);
|
||||
ptr = start = mtod(m, const u_char *);
|
||||
|
||||
/* Must be UI frame */
|
||||
if (*ptr++ != HDLC_UI)
|
||||
@ -237,7 +238,7 @@ ng_rfc1490_rcvdata(hook_p hook, item_p item)
|
||||
u_int16_t etype;
|
||||
|
||||
ptr += 3;
|
||||
etype = ntohs(*((u_int16_t *) ptr));
|
||||
etype = ntohs(*((const u_int16_t *)ptr));
|
||||
ptr += 2;
|
||||
m_adj(m, ptr - start);
|
||||
switch (etype) {
|
||||
|
@ -571,7 +571,7 @@ ng_detach_common(struct ngpcb *pcbp, int which)
|
||||
static int
|
||||
ng_internalize(struct mbuf *control, struct thread *td)
|
||||
{
|
||||
struct cmsghdr *cm = mtod(control, struct cmsghdr *);
|
||||
const struct cmsghdr *cm = mtod(control, const struct cmsghdr *);
|
||||
struct file *fp;
|
||||
struct vnode *vn;
|
||||
int oldfds;
|
||||
|
Loading…
Reference in New Issue
Block a user