Change definition of NG_BPF_HOOKPROG_SIZE() so as not to require
a structure pointer, just the number of BPF instructions.
This commit is contained in:
parent
820379186b
commit
ab0d3c94db
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=54214
@ -279,7 +279,8 @@ ng_bpf_rcvmsg(node_p node, struct ng_mesg *msg, const char *retaddr,
|
||||
|
||||
/* Sanity check */
|
||||
if (msg->header.arglen < sizeof(*hp)
|
||||
|| msg->header.arglen != NG_BPF_HOOKPROG_SIZE(hp))
|
||||
|| msg->header.arglen
|
||||
!= NG_BPF_HOOKPROG_SIZE(hp->bpf_prog_len))
|
||||
ERROUT(EINVAL);
|
||||
|
||||
/* Find hook */
|
||||
@ -294,8 +295,8 @@ ng_bpf_rcvmsg(node_p node, struct ng_mesg *msg, const char *retaddr,
|
||||
|
||||
case NGM_BPF_GET_PROGRAM:
|
||||
{
|
||||
struct ng_bpf_hookprog *hp;
|
||||
hook_p hook;
|
||||
hinfo_p hip;
|
||||
|
||||
/* Sanity check */
|
||||
if (msg->header.arglen == 0)
|
||||
@ -305,15 +306,15 @@ ng_bpf_rcvmsg(node_p node, struct ng_mesg *msg, const char *retaddr,
|
||||
/* Find hook */
|
||||
if ((hook = ng_findhook(node, msg->data)) == NULL)
|
||||
ERROUT(ENOENT);
|
||||
hip = hook->private;
|
||||
|
||||
/* Build response */
|
||||
hp = ((hinfo_p)hook->private)->prog;
|
||||
NG_MKRESPONSE(resp, msg,
|
||||
NG_BPF_HOOKPROG_SIZE(hip->prog), M_NOWAIT);
|
||||
NG_BPF_HOOKPROG_SIZE(hp->bpf_prog_len), M_NOWAIT);
|
||||
if (resp == NULL)
|
||||
ERROUT(ENOMEM);
|
||||
bcopy(hip->prog, resp->data,
|
||||
NG_BPF_HOOKPROG_SIZE(hip->prog));
|
||||
bcopy(hp, resp->data,
|
||||
NG_BPF_HOOKPROG_SIZE(hp->bpf_prog_len));
|
||||
break;
|
||||
}
|
||||
|
||||
@ -486,7 +487,7 @@ ng_bpf_setprog(hook_p hook, const struct ng_bpf_hookprog *hp0)
|
||||
return (EINVAL);
|
||||
|
||||
/* Make a copy of the program */
|
||||
size = NG_BPF_HOOKPROG_SIZE(hp0);
|
||||
size = NG_BPF_HOOKPROG_SIZE(hp0->bpf_prog_len);
|
||||
MALLOC(hp, struct ng_bpf_hookprog *, size, M_NETGRAPH, M_WAITOK);
|
||||
if (hp == NULL)
|
||||
return (ENOMEM);
|
||||
|
@ -56,8 +56,8 @@ struct ng_bpf_hookprog {
|
||||
struct bpf_insn bpf_prog[0]; /* bpf program */
|
||||
};
|
||||
|
||||
#define NG_BPF_HOOKPROG_SIZE(hp) \
|
||||
(sizeof(*(hp)) + (hp)->bpf_prog_len * sizeof((hp)->bpf_prog[0]))
|
||||
#define NG_BPF_HOOKPROG_SIZE(numInsn) \
|
||||
(sizeof(struct ng_bpf_hookprog) + (numInsn) * sizeof(struct bpf_insn))
|
||||
|
||||
/* Keep this in sync with the above structure definition */
|
||||
#define NG_BPF_HOOKPROG_TYPE_INFO(bptype) { \
|
||||
|
Loading…
Reference in New Issue
Block a user