public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Dan Carpenter <dan.carpenter@oracle.com>
To: Dominik Paulus <dominik.paulus@fau.de>
Cc: Anthony Foiani <anthony.foiani@gmail.com>,
	devel@driverdev.osuosl.org, linux-kernel@i4.cs.fau.de,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Kurt Kanzenbach <ly80toro@cip.cs.fau.de>,
	tobias.polzer@fau.de, linux-kernel@vger.kernel.org,
	Ilija Hadzic <ihadzic@research.bell-labs.com>
Subject: Re: [PATCHv4 10/16] staging: usbip: TLS for all userspace communication
Date: Fri, 25 Oct 2013 17:45:50 +0300	[thread overview]
Message-ID: <20131025144549.GG5871@mwanda> (raw)
In-Reply-To: <1382193559-12549-11-git-send-email-dominik.paulus@fau.de>

On Sat, Oct 19, 2013 at 04:39:13PM +0200, Dominik Paulus wrote:
> @@ -104,8 +105,10 @@ static int import_device(int sockfd, struct usbip_usb_device *udev)
>  		return -1;
>  	}
>  
> -	rc = usbip_vhci_attach_device(port, sockfd, udev->busnum,
> +	usbip_net_bye(conn);
> +	rc = usbip_vhci_attach_device(port, conn->sockfd, udev->busnum,
>  				      udev->devnum, udev->speed);
> +
>  	if (rc < 0) {

Don't put a blank line between the function call and the check.  They
logically are one idea.

>  
> -	rc = usbip_net_recv(sockfd, (void *) &reply, sizeof(reply));
> +	rc = usbip_net_recv(conn, (void *) &reply, sizeof(reply));

There is no need to cast to void here, btw.  That's just noise.

>  	do {
> -		if (sending)
> -			nbytes = send(sockfd, buff, bufflen, 0);
> +		if (!conn->have_crypto && sending)
> +			nbytes = send(conn->sockfd, buff, bufflen, 0);
> +		else if (!conn->have_crypto && !sending)
> +			nbytes = recv(conn->sockfd, buff, bufflen, MSG_WAITALL);
> +#ifdef HAVE_GNUTLS
> +		else if (sending)
> +			nbytes = gnutls_record_send(conn->session, buff, bufflen);
>  		else
> -			nbytes = recv(sockfd, buff, bufflen, MSG_WAITALL);
> +			nbytes = gnutls_record_recv(conn->session, buff, bufflen);
> +#else
> +		/*
> +		 * Assertion to let gcc be able to infer proper initialization
> +		 * of nbytes.
> +		 */
> +		assert(!conn->have_crypto);
> +#endif

This is messy and I feel like it should be abstracted into a function
so we can hide the ifdef in a header file.

		if (sending)
			nbytes = usbip_send(conn, buff, bufflen, 0);
		else
			nbytes = usbip_recv(...

We'd still have the ifdef but hidden away.


> +int usbip_net_srp_server_handshake(struct usbip_connection *conn)
> +{
> +	int ret;
> +
> +	if (gnutls_init(&conn->session, GNUTLS_SERVER) != 0)
> +		return -1;
> +	gnutls_priority_set_direct(conn->session, "NORMAL:-KX-ALL:+SRP", NULL);
> +	if (gnutls_credentials_set(conn->session, GNUTLS_CRD_SRP,
> +		usbip_net_srp_cred) != 0)
> +		return -1;
> +

Kernel style is more beautiful:

	ret = gnutls_credentials_set(conn->session, GNUTLS_CRD_SRP,
				     usbip_net_srp_cred);
	if (ret)
		return ret;

> +void usbip_net_bye(struct usbip_connection *conn)
> +{
> +#ifdef HAVE_GNUTLS
> +	if (conn->have_crypto) {
> +		gnutls_bye(conn->session, GNUTLS_SHUT_RDWR);
> +
> +		gnutls_deinit(conn->session);
> +		if (!conn->server)
> +			gnutls_srp_free_client_credentials(conn->srp_client_cred);
> +
> +		conn->have_crypto = 0;
> +	}
> +#else
> +	(void)conn;

What is this about?  I assume that GCC warns, but which version of GCC
are you using because that sounds horrible.

> +#endif

regards,
dan carpenter

  reply	other threads:[~2013-10-25 14:46 UTC|newest]

Thread overview: 53+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-09-13  9:55 [PATCHv2 0/11] staging: usbip: Userland crypto and ACLs Dominik Paulus
2013-09-13  9:55 ` [PATCHv2 01/11] staging: usbip: Fix IPv6 support in usbipd Dominik Paulus
2013-09-13  9:55 ` [PATCHv2 02/11] staging: usbip: Add support for client authentication Dominik Paulus
2013-09-13  9:55 ` [PATCHv2 03/11] staging: usbip: Add kernel support for client ACLs Dominik Paulus
2013-09-13  9:55 ` [PATCHv2 04/11] staging: usbip: Add CIDR matching helper functions Dominik Paulus
2013-09-13  9:55 ` [PATCHv2 05/11] staging: usbip: Add ACL support to usbip bind Dominik Paulus
2013-09-13  9:55 ` [PATCHv2 06/11] staging: usbip: Add support for ACLs in usbipd Dominik Paulus
2013-09-13  9:55 ` [PATCHv2 07/11] staging: usbip: Add proper error reporting Dominik Paulus
2013-09-13  9:55 ` [PATCHv2 08/11] staging: usbip: Handle usbip being started as user Dominik Paulus
2013-09-13  9:55 ` [PATCHv2 09/11] staging: usbip: Improve debug output Dominik Paulus
2013-09-13  9:56 ` [PATCHv2 10/11] staging: usbip: Separate protocol/program version Dominik Paulus
2013-09-13  9:56 ` [PATCHv2 11/11] staging: usbip: Increment version to 1.2.0 Dominik Paulus
2013-09-25 23:36 ` [PATCHv2 0/11] staging: usbip: Userland crypto and ACLs Greg Kroah-Hartman
2013-09-28 17:41   ` Dominik Paulus
2013-09-28 17:42   ` [PATCHv3 01/16] staging: usbip: Add support for client authentication Dominik Paulus
2013-09-28 17:42     ` [PATCHv3 02/16] staging: usbip: Add kernel support for client ACLs Dominik Paulus
2013-09-30  8:29       ` Dan Carpenter
2013-09-28 17:42     ` [PATCHv3 03/16] staging: usbip: Add CIDR matching helper functions Dominik Paulus
2013-09-28 17:42     ` [PATCHv3 04/16] staging: usbip: Add ACL support to usbip bind Dominik Paulus
2013-09-28 17:42     ` [PATCHv3 05/16] staging: usbip: Add support for ACLs in usbipd Dominik Paulus
2013-09-28 17:42     ` [PATCHv3 06/16] staging: usbip: Add proper error reporting Dominik Paulus
2013-09-28 17:42     ` [PATCHv3 07/16] staging: usbip: Handle usbip being started as user Dominik Paulus
2013-09-28 17:42     ` [PATCHv3 08/16] staging: usbip: Improve debug output Dominik Paulus
2013-09-28 17:42     ` [PATCHv3 09/16] staging: usbip: Separate protocol/program version Dominik Paulus
2013-09-28 17:42     ` [PATCHv3 10/16] staging: usbip: TLS for all userspace communication Dominik Paulus
2013-09-28 17:42     ` [PATCHv3 11/16] staging: usbip: Exchange session keys in userspace Dominik Paulus
2013-09-28 17:42     ` [PATCHv3 12/16] staging: usbip: Pass session keys to the kernel Dominik Paulus
2013-09-28 17:42     ` [PATCHv3 13/16] staging: usbip: Wrap kernel_sendmsg()/recvmsg() Dominik Paulus
2013-09-30 12:42       ` Dan Carpenter
2013-09-28 17:42     ` [PATCHv3 14/16] staging: usbip: Add encryption support to kernel Dominik Paulus
2013-09-30 12:38       ` Dan Carpenter
2013-10-19 14:39         ` [PATCHv4 00/16] staging: usbip: Add kernel support for client ACLs Dominik Paulus
2013-10-19 14:39           ` [PATCHv4 01/16] staging: usbip: Add support for client authentication Dominik Paulus
2013-10-19 14:39           ` [PATCHv4 02/16] staging: usbip: Add kernel support for client ACLs Dominik Paulus
2013-10-19 14:39           ` [PATCHv4 03/16] staging: usbip: Add CIDR matching helper functions Dominik Paulus
2013-10-19 14:39           ` [PATCHv4 04/16] staging: usbip: Add ACL support to usbip bind Dominik Paulus
2013-10-19 14:39           ` [PATCHv4 05/16] staging: usbip: Add support for ACLs in usbipd Dominik Paulus
2013-10-19 14:39           ` [PATCHv4 06/16] staging: usbip: Add proper error reporting Dominik Paulus
2013-10-25 13:26             ` Dan Carpenter
2013-10-19 14:39           ` [PATCHv4 07/16] staging: usbip: Handle usbip being started as user Dominik Paulus
2013-10-19 14:39           ` [PATCHv4 08/16] staging: usbip: Improve debug output Dominik Paulus
2013-10-19 14:39           ` [PATCHv4 09/16] staging: usbip: Separate protocol/program version Dominik Paulus
2013-10-19 14:39           ` [PATCHv4 10/16] staging: usbip: TLS for all userspace communication Dominik Paulus
2013-10-25 14:45             ` Dan Carpenter [this message]
2013-10-19 14:39           ` [PATCHv4 11/16] staging: usbip: Exchange session keys in userspace Dominik Paulus
2013-10-19 14:39           ` [PATCHv4 12/16] staging: usbip: Pass session keys to the kernel Dominik Paulus
2013-10-25 15:02             ` Dan Carpenter
2013-10-19 14:39           ` [PATCHv4 13/16] staging: usbip: Wrap kernel_sendmsg()/recvmsg() Dominik Paulus
2013-10-19 14:39           ` [PATCHv4 14/16] staging: usbip: Add encryption support to kernel Dominik Paulus
2013-10-19 14:39           ` [PATCHv4 15/16] staging: usbip: Update documentation Dominik Paulus
2013-10-19 14:39           ` [PATCHv4 16/16] staging: usbip: Increment version number to 1.2.1 Dominik Paulus
2013-09-28 17:42     ` [PATCHv3 15/16] staging: usbip: Update documentation Dominik Paulus
2013-09-28 17:42     ` [PATCHv3 16/16] staging: usbip: Increment version number to 1.2.1 Dominik Paulus

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=20131025144549.GG5871@mwanda \
    --to=dan.carpenter@oracle.com \
    --cc=anthony.foiani@gmail.com \
    --cc=devel@driverdev.osuosl.org \
    --cc=dominik.paulus@fau.de \
    --cc=gregkh@linuxfoundation.org \
    --cc=ihadzic@research.bell-labs.com \
    --cc=linux-kernel@i4.cs.fau.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ly80toro@cip.cs.fau.de \
    --cc=tobias.polzer@fau.de \
    /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