From: Eric Blake <eblake@redhat.com>
To: "Anton Ivanov (antivano)" <antivano@cisco.com>,
Paolo Bonzini <pbonzini@redhat.com>
Cc: "Qemu-devel@nongnu.org" <Qemu-devel@nongnu.org>,
Stefan Hajnoczi <stefanha@redhat.com>
Subject: Re: [Qemu-devel] Contribution - L2TPv3 transport
Date: Tue, 04 Mar 2014 09:33:41 -0700 [thread overview]
Message-ID: <53160065.50908@redhat.com> (raw)
In-Reply-To: <5315EEFE.6060605@cisco.com>
[-- Attachment #1: Type: text/plain, Size: 6176 bytes --]
On 03/04/2014 08:19 AM, Anton Ivanov (antivano) wrote:
> Attached is a revised version.
>
> +
> +
> +#define PAGE_SIZE 4096
One of your earlier review comments suggested using sysconf or else
renaming this, as not all systems have a page size of 4096.
> +#define IOVSIZE 2
> +#define MAX_L2TPV3_MSGCNT 32
> +#define MAX_L2TPV3_IOVCNT (MAX_L2TPV3_MSGCNT * IOVSIZE)
> +
> +#ifndef IPPROTO_L2TP
> +#define IPPROTO_L2TP 0x73
> +#endif
> +
> +typedef struct NetL2TPV3State {
> + NetClientState nc;
> + int fd;
> + int state;
> + unsigned int index;
> + unsigned int packet_len;
> +
> + /*
> + * these are used for xmit - that happens packet a time
> + * and for first sign of life packet (easier to parse that once)
> + */
> +
> + uint8_t * header_buf;
Most code uses this style:
uint8_t *header_buf;
with no space between a pointer designation and the variable name it
applies to (several instances in your patch).
> +
> + /*
> + * Bitmask mode determining encaps behaviour
> + */
> +
> + uint32_t offset;
> + uint32_t cookie_offset;
> + uint32_t counter_offset;
> + uint32_t session_offset;
Comment is off, as there is no bitmask here.
> +static int l2tpv3_form_header(NetL2TPV3State *s) {
> + uint32_t *header;
> + uint32_t *session;
> + uint64_t *cookie64;
> + uint32_t *cookie32;
> + uint32_t *counter;
> +
> + if (s->udp == TRUE) {
We require a C99 compiler; use 'true' not 'TRUE' (glib's TRUE caters
mainly to C89 compilers, and isn't necessarily a true boolean). For
that matter, comparison against true or false is verbose; it's fine to
just use:
if (s->udp) {
> + header = (uint32_t *) s->header_buf;
> + stl_be_p(header, 0x30000);
> + }
> + session = (uint32_t *) (s->header_buf + s->session_offset);
> + stl_be_p(session, s->tx_session);
> +
> + if (s->cookie == TRUE ) {
> + if (s->cookie_is_64 == TRUE) {
More cases of TRUE that should be fixed. Also, no space before ).
> + if (s->nocounter == FALSE) {
> + counter = (uint32_t *)(s->header_buf + s->counter_offset);
> + stl_be_p(counter, ++ s->counter);
> + }
TAB damage - we indent with spaces. No space after preincrement ++.
> + return 0;
> +}
> +
> +static ssize_t net_l2tpv3_receive_dgram_iov(NetClientState *nc, const struct iovec *iov, int iovcnt)
Long line; you can split after , to fit within 80 columns.
> +{
> + NetL2TPV3State *s = DO_UPCAST(NetL2TPV3State, nc, nc);
> +
> + struct msghdr message;
> + int ret;
> +
> + if (iovcnt > MAX_L2TPV3_IOVCNT - 1) {
> + fprintf(stderr, "iovec too long %d > %d, change l2tpv3.h\n", iovcnt, MAX_L2TPV3_IOVCNT);
> + return -1;
Is printing to stderr always the right thing to do? It seems to me that
you should look into using QError.
> + if (ret < 0) {
> + ret = - errno;
> + } else if (ret == 0) {
> + ret = iov_size (iov, iovcnt);
No space before ( in function calls.
> + vec++;
> + vec->iov_base = (void *) buf;
This is C, not C++ - no need to cast to (void*).
> + if (ret < 0) {
> + ret = - errno;
No space after unary '-'.
> + } else if (ret == 0) {
> + ret = size;
> + } else {
> + ret =- s->offset;
Trailing whitespace. Please run your submission through
scripts/checkpatch.pl, and address all warnings.
'=-' looks odd; did you mean '= -'?
> +
> +static int l2tpv3_verify_header(NetL2TPV3State *s, uint8_t *buf) {
Opening { on its own line.
> +
> + uint64_t *cookie64;
> + uint32_t *cookie32;
> + uint32_t *session;
> +
> + if ((s->udp == FALSE) && (s->ipv6 == FALSE)){
Too many (), missing space before { - this should be:
if (!s->udp && !s->ipv6) {
> + buf += sizeof(struct iphdr) /* fix for ipv4 raw */;
> + }
> + if (s->cookie == TRUE) {
> + if (s->cookie_is_64 == TRUE) {
> + /* 64 bit cookie */
> + cookie64 = (uint64_t *)(buf + s->cookie_offset);
> + if ( ldq_be_p(cookie64) != s->rx_cookie) {
> + fprintf(stderr, "unknown cookie id\n");
> + return -1; /* we need to return 0, otherwise barfus */
What's up with that comment being different from the code?
> + }
> + } else {
> + cookie32 = (uint32_t *)(buf + s->cookie_offset);
> + if (ldl_be_p(cookie32) != * (uint32_t *) &s->rx_cookie) {
> + fprintf(stderr,"unknown cookie id\n");
Space after ','. Again, I think QError is better than directly printing
to stderr.
> + return -1 ; /* we need to return 0, otherwise barfus */
> + }
> + }
> + }
> + session = (uint32_t *) (buf + s->session_offset);
> + if (ldl_be_p(session) != s->rx_session) {
Are you risking bus errors on platforms where you cannot dereference a
wide int pointer that gets set to a misaligned offset?
> + msgvec = s->msgvec;
> + offset = s->offset;
> + if ((s->udp == FALSE) && (s->ipv6 == FALSE)){
> + offset += sizeof(struct iphdr);
> + }
Whitespace damage.
> + count = recvmmsg(s->fd, msgvec, MAX_L2TPV3_MSGCNT, MSG_DONTWAIT, NULL);
> + for (i=0;i<count;i++) {
Should be:
for (i = 0; i < count; i++) {
Lots of other sites need similar fixes.
> +
> + if ((getaddrinfo(l2tpv3->src, srcport, &hints, &result) !=0) || (result == NULL)) {
> + fd = -errno;
> + fprintf(stderr, "l2tpv3_open : could not resolve src, " "errno = %d\n", fd);
What's up with the string concatenation in the format string?
getaddrinfo() does NOT set errno. Rather, it returns a code that you
decipher with gai_strerror(). Your error reporting here is very suspect.
> +++ b/net/net.c
> @@ -731,6 +731,9 @@ static int (* const net_client_init_fun[NET_CLIENT_OPTIONS_KIND_MAX])(
> [NET_CLIENT_OPTIONS_KIND_BRIDGE] = net_init_bridge,
> #endif
> [NET_CLIENT_OPTIONS_KIND_HUBPORT] = net_init_hubport,
> +#ifdef CONFIG_LINUX
> + [NET_CLIENT_OPTIONS_KIND_L2TPV3] = net_init_l2tpv3,
> +#endif
Alignment looks off.
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 604 bytes --]
next prev parent reply other threads:[~2014-03-04 16:34 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-02-28 8:28 [Qemu-devel] Contribution - L2TPv3 transport Anton Ivanov (antivano)
2014-02-28 10:02 ` Paolo Bonzini
2014-02-28 11:17 ` Anton Ivanov (antivano)
2014-02-28 11:36 ` Paolo Bonzini
2014-02-28 12:59 ` Anton Ivanov (antivano)
2014-02-28 13:55 ` Anton Ivanov (antivano)
2014-03-04 15:19 ` Anton Ivanov (antivano)
2014-03-04 15:22 ` Anton Ivanov (antivano)
2014-03-04 15:53 ` Eric Blake
2014-03-04 16:05 ` Anton Ivanov (antivano)
2014-03-05 8:49 ` Anton Ivanov (antivano)
2014-03-05 11:38 ` Peter Maydell
2014-03-04 15:41 ` Eric Blake
2014-03-04 15:58 ` Anton Ivanov (antivano)
2014-03-04 16:04 ` Paolo Bonzini
2014-03-04 16:33 ` Eric Blake [this message]
2014-03-04 16:48 ` Anton Ivanov (antivano)
2014-03-04 16:55 ` Paolo Bonzini
2014-03-04 17:28 ` Anton Ivanov (antivano)
2014-03-04 17:30 ` Paolo Bonzini
2014-02-28 13:40 ` Eric Blake
2014-02-28 13:52 ` Anton Ivanov (antivano)
2014-02-28 13:57 ` Eric Blake
2014-02-28 14:03 ` Anton Ivanov (antivano)
2014-02-28 14:00 ` Paolo Bonzini
2014-02-28 15:06 ` Eric Blake
2014-02-28 15:20 ` Paolo Bonzini
2014-03-03 13:27 ` Stefan Hajnoczi
2014-03-03 14:01 ` Anton Ivanov (antivano)
2014-03-04 9:36 ` Stefan Hajnoczi
2014-03-04 9:47 ` Anton Ivanov (antivano)
2014-03-05 8:59 ` Stefan Hajnoczi
2014-03-05 9:13 ` Vincenzo Maffione
2014-03-03 14:53 ` Stefan Hajnoczi
2014-03-04 11:32 ` Anton Ivanov (antivano)
2014-03-05 9:07 ` Stefan Hajnoczi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=53160065.50908@redhat.com \
--to=eblake@redhat.com \
--cc=Qemu-devel@nongnu.org \
--cc=antivano@cisco.com \
--cc=pbonzini@redhat.com \
--cc=stefanha@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).