Skip to content

Commit 62cca46

Browse files
author
Luigi Rizzo
committed
style fixes, and make errors positive as standard in FreeBSD
1 parent 1b2b5f6 commit 62cca46

File tree

5 files changed

+43
-37
lines changed

5 files changed

+43
-37
lines changed

bsd_nlsock.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ netlink_attach(struct socket *so, int proto, struct thread *td)
199199
struct rawcb *rp;
200200
int error;
201201

202-
D("so %p thread %p", _P32(so), _P32(td));
202+
ND("so %p thread %p", _P32(so), _P32(td));
203203
KASSERT(so->so_pcb == NULL, ("netlink_attach: so_pcb != NULL"));
204204

205205
error = bsd_nl_proto_check(proto);
@@ -256,7 +256,7 @@ netlink_connect(struct socket *so, struct sockaddr *nam, struct thread *td)
256256
so->nl_src_portid = atomic_fetchadd_32(&netlinkpids, 1);
257257
so->nl_dst_portid = nla->nl_pid; /* not used */
258258

259-
D("src_portid %d dst_portid %d", so->nl_src_portid, so->nl_dst_portid);
259+
ND("src_portid %d dst_portid %d", so->nl_src_portid, so->nl_dst_portid);
260260
soisconnected(so);
261261

262262
return 0;

genetlink.c

+20-12
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ genl_register_family_with_ops(struct genl_family *family,
9393
* should try assign that as family id
9494
*/
9595
if (idfamily != GENL_ID_GENERATE)
96-
return -EEXIST;
96+
return EEXIST;
9797
/* TODO: id generation should be done better */
9898
idfamily = atomic_fetchadd_int(&cur_max_genl_family, 1);
9999

@@ -238,7 +238,7 @@ genetlink_call_op_dumpit(const struct genl_ops *curop,
238238
genl_unlock();
239239

240240
/* If no error avoid ack */
241-
return (res == 0)?-EINTR:res;
241+
return (res == 0) ? EINTR : res;
242242
}
243243

244244
static int
@@ -284,24 +284,30 @@ genetlink_receive_message(char *data)
284284
break;
285285
}
286286

287+
D("process family %d %p", idfamily, curfamily);
288+
287289
if (curfamily == NULL)
288-
return -ENOENT;
290+
return ENOENT;
289291

290292
/* check if we have space */
291-
if (curfamily->maxattr + 1 > _GNL_MAX_ATTR)
292-
return -ENOMEM;
293+
if (curfamily->maxattr + 1 > _GNL_MAX_ATTR) {
294+
D("no space to process attributes");
295+
return ENOMEM;
296+
}
293297

294298
ops = curfamily->ops;
295299

296300
genlmsg = (struct genlmsghdr *)(data + NLMSG_HDRLEN);
297301
numop = genlmsg->cmd;
302+
D("cmd is %d look into %d options", numop, curfamily->n_ops);
298303
for (i = 0; i < curfamily->n_ops; ++i) {
299-
if(ops[i].cmd == numop)
304+
if (ops[i].cmd == numop)
300305
break;
301306
}
302307

303-
if (i >= curfamily->n_ops)
304-
return -EOPNOTSUPP;
308+
if (i >= curfamily->n_ops) {
309+
return EOPNOTSUPP;
310+
}
305311

306312
curop = &(curfamily->ops[i]);
307313

@@ -319,8 +325,10 @@ genetlink_receive_message(char *data)
319325

320326
info.attrs = attrs;
321327
err = genl_parse_info(data, curfamily, curop->policy, &info);
322-
if (err)
328+
if (err) {
329+
D("genl_parse_info returns error %d", err);
323330
return err;
331+
}
324332

325333
/* XXX remove this log */
326334
log(LOG_INFO, "myhandler:idfamily:%d, numop%d %s\n",
@@ -332,7 +340,7 @@ genetlink_receive_message(char *data)
332340
} else if(!(nlmsg->nlmsg_flags & NLM_F_DUMP) && curop->doit) {
333341
err = genetlink_call_op_doit(curop, nlmsg, &info);
334342
} else {
335-
return -EOPNOTSUPP;
343+
return EOPNOTSUPP;
336344
}
337345

338346
return err;
@@ -407,15 +415,15 @@ genl_ctrl_lookup_family(struct mbuf *m, struct genl_info * info)
407415

408416
/* TODO:implement also lookup by id */
409417
if (nlaname == NULL)
410-
return -EINVAL;
418+
return EINVAL;
411419

412420
LIST_FOREACH(family, &genl_family_list, family_list) {
413421
if (strncmp(family->name, familyname, GENL_NAMSIZ) == 0)
414422
break;
415423
}
416424

417425
if (family == NULL)
418-
return -ENOENT;
426+
return ENOENT;
419427

420428
/* Family found!! */
421429
reply = nlmsg_new(NLMSG_DEFAULT_SIZE, M_WAITOK);

linux/netlink.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ struct mbuf; /* we must be compilable with an opaque type */
134134

135135
#else /* __COMPAT_MBUF_TYPE */ /* mbufs are remapped XXX */
136136
/* returns a readonly object */
137-
struct netlink_skb_parms NETLINK_CB(struct mbuf *);
137+
// struct netlink_skb_parms NETLINK_CB(struct mbuf *);
138138
#endif /* !__COMPAT_MBUF_TYPE */
139139

140140
struct netlink_skb_parms { /* XXX needs work */

net/genetlink.h

+3-4
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,10 @@ struct genl_ops {
102102
struct genl_info *info);
103103
int (*dumpit)(struct mbuf *m,
104104
struct netlink_callback *cb);
105-
#if 0
106-
/* TODO: fields not used by openvswitch */
105+
#if 0 /* TODO: fields not used by openvswitch */
107106
int (*done)(struct netlink_callback *cb);
108107
struct list_head ops_list;
109-
#endif
108+
#endif
110109
};
111110

112111
struct genl_info {
@@ -161,7 +160,7 @@ genl_set_err(struct genl_family *fam, struct net *net,
161160
uint32_t portid, uint32_t group, uint32_t code)
162161
{
163162
if (group >= fam->mcgrp_offset)
164-
return -EINVAL;
163+
return EINVAL;
165164
group += fam->mcgrp_offset;
166165
/* we do not support namespaces yet */
167166
netlink_set_err(NULL /* net->genl_sock */, portid, group, code);

netlink.c

+17-18
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,6 @@ static const uint16_t nla_attr_minlen[NLA_TYPE_MAX+1] = {
104104
};
105105

106106
/*
107-
* These validate functions return a negative error number because
108-
* the nla_parse(), a linux API, does so.
109107
* XXX nla_type() is really a sequence number in the policy definition.
110108
*/
111109
static int
@@ -124,12 +122,12 @@ validate_nla(const struct nlattr *nla, int maxtype,
124122

125123
pt = &policy[atype];
126124
if (pt->type > NLA_TYPE_MAX) /* error in the policy! */
127-
return -EINVAL;
125+
return EINVAL;
128126

129127
plen = pt->len; /* how much space is allowed by policy ? */
130128
switch (pt->type) {
131129
case NLA_FLAG:
132-
return (alen != 0) ? -ERANGE : 0; /* nla error */
130+
return (alen != 0) ? ERANGE : 0; /* nla error */
133131

134132
case NLA_NUL_STRING: /* plen excludes the NUL */
135133
/*
@@ -139,41 +137,41 @@ validate_nla(const struct nlattr *nla, int maxtype,
139137
if (plen && plen+1 < alen)
140138
alen = plen + 1;
141139
if (alen == 0)
142-
return -EINVAL;
140+
return EINVAL;
143141

144142
/* Search for NUL termination */
145143
for (i = 0; i < alen; i++) {
146144
if (data[i] == 0)
147145
return 0; /* all fine */
148146
}
149-
return -EINVAL; /* missing terminator */
147+
return EINVAL; /* missing terminator */
150148

151149
case NLA_STRING: /* non terminated strings */
152150
if (alen == 0) /* empty strings not allowed */
153-
return -ERANGE;
151+
return ERANGE;
154152
if (plen) { /* check the limit */
155153
if (data[alen - 1] == 0)
156154
alen--;
157155
if (alen > plen)
158-
return -ERANGE;
156+
return ERANGE;
159157
}
160158
return 0;
161159

162160
case NLA_BINARY:
163-
return (plen && alen > plen) ? -ERANGE : 0;
161+
return (plen && alen > plen) ? ERANGE : 0;
164162

165163
case NLA_NESTED_COMPAT:
166164
/* plen indicates minimum alen */
167165
if (alen < plen) /* too short */
168-
return -ERANGE;
166+
return ERANGE;
169167
if (alen < NLA_ALIGN(plen)) /* ok (including padding */
170168
break;
171169
/* if alen >= plen we need another header */
172170
if (alen < NLA_ALIGN(plen) + NLA_HDRLEN)
173-
return -ERANGE;
171+
return ERANGE;
174172
nla = (const struct nlattr *)(data + NLA_ALIGN(plen));
175173
if (alen < NLA_ALIGN(plen) + NLA_HDRLEN + nla_len(nla))
176-
return -ERANGE;
174+
return ERANGE;
177175
break;
178176

179177
case NLA_NESTED:
@@ -187,10 +185,10 @@ validate_nla(const struct nlattr *nla, int maxtype,
187185
default:
188186
if (plen) {
189187
if (alen < plen)
190-
return -ERANGE;
188+
return ERANGE;
191189
} else if (pt->type != NLA_UNSPEC) {
192190
if (alen < nla_attr_minlen[pt->type])
193-
return -ERANGE;
191+
return ERANGE;
194192
} /* else pass */
195193
}
196194

@@ -366,7 +364,7 @@ netlink_receive_packet(struct mbuf *m, struct socket *so, int proto)
366364
int old_l = datalen;
367365
(void)old_l;
368366
datalen = (l + 0x3ff) & ~0x3ff; /* round to 1k */
369-
ND("reallocate buffer %d -> %d [%d]",
367+
D("reallocate buffer %d -> %d [%d]",
370368
old_l, l, datalen);
371369
if (buf != NULL) {
372370
free(buf, M_NETLINK);
@@ -378,12 +376,13 @@ netlink_receive_packet(struct mbuf *m, struct socket *so, int proto)
378376
return ENOMEM;
379377
}
380378
}
381-
ND("Copy the whole message");
379+
ND("Copy message, including header");
382380
m_copydata(m, ofs, l, buf);
383381
h = (struct nlmsghdr *)buf;
384382
if (h->nlmsg_flags & NLM_F_REQUEST &&
385383
h->nlmsg_type >= NLMSG_MIN_TYPE) {
386-
D("process the callback");
384+
D("msg_type %d callback %p len %d",
385+
h->nlmsg_type, _P32(cb), l);
387386
err = cb((void *)h);
388387
D("callback returns %d", err);
389388
}
@@ -409,7 +408,7 @@ nla_put(struct mbuf *m, int attrtype, int attrlen, const void *data)
409408
size_t need = NLMSG_ALIGN(totlen);
410409

411410
if (m->m_pkthdr.len + need > _ML(m))
412-
return -EMSGSIZE;
411+
return EMSGSIZE;
413412
nla = (struct nlattr *)_MC(m);
414413
bzero(nla, NLA_HDRLEN);
415414
nla->nla_len = totlen;

0 commit comments

Comments
 (0)