Skip to contentSkip to conversation

AF_RXRPC socket family implementation

RFC PATCH In review David Howells 5 participants 18 messages Feb 8, 2007 – Feb 22, 2007

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

cover AF_RXRPC socket family implementation

These patches together supply secure client-side RxRPC connectivity as a Linux kernel socket family. Only the transport/session side is supplied - the presentation side (marshalling the data) is left to the client.

The userspace access methods make use of the control data passed to/by sendmsg() and recvmsg(). See the two simple test programs:

http://people.redhat.com/~dhowells/rxrpc/klog.c
http://people.redhat.com/~dhowells/rxrpc/rxrpc.c

I've attached the current in-kernel documentation to this message.

TODO:

(*) Server support.

(*) Make it possible for the client socket to be used to go to more than one
destination.

(*) Make fs/afs/ use it and delete the current contents of net/rxrpc/

(*) Make certain parameters (such as connection timeouts) userspace
configurable.

(*) Make userspace utilities use it; librxrpc.

(*) Userspace documentation.

David

			    ======================
			    RxRPC NETWORK PROTOCOL
			    ======================

The RxRPC protocol driver provides a reliable two-phase transport on top of UDP that can be used to perform RxRPC remote operations. This is done over sockets of AF_RXRPC family, using sendmsg() and recvmsg() with control data to send and receive data, aborts and errors.

========
OVERVIEW
========

RxRPC is a two-layer protocol. There is a session layer which provides reliable virtual connections using UDP over IPv4 (or IPv6) as the transport layer, but implements a real network protocol; and there's the presentation layer which renders structured data to binary blobs and back again using XDR (as does SunRPC):

		+-------------+
		| Application |
		+-------------+
		|     XDR     |		Presentation
		+-------------+
		|    RxRPC    |		Session
		+-------------+
		|     UDP     |		Transport
		+-------------+

AF_RXRPC provides:

(1) Part of an RxRPC facility for both kernel and userspace applications by making the session part of it a Linux network protocol (AF_RXRPC).

(2) A two-phase protocol. The client transmits a blob (the request) and then receives a blob (the reply), and the server receives the request and then transmits the reply.

(3) Retention of the reusable bits of the transport system set up for one call to speed up subsequent calls.

(4) A secure protocol, using the Linux kernel's key retention facility to manage security on the client end. The server end must of necessity be more active in security negotiations.

AF_RXRPC does not provide XDR marshalling/presentation facilities. That is left to the application. AF_RXRPC only deals in blobs. Even the operation ID is just the first four bytes of the request blob, and as such is beyond the kernel's interest.

Sockets of AF_RXRPC family are:

(1) created as type SOCK_RPC;

(2) provided with a protocol of the type of underlying transport they're going to use - currently only PF_INET is supported.

The Andrew File System (AFS) is an example of an application that uses this and that has both kernel (filesystem) and userspace (utility) components.

======================
RXRPC PROTOCOL SUMMARY
======================

An overview of the RxRPC protocol:

(*) RxRPC sits on top of another networking protocol (UDP is the only option
currently), and uses this to provide network transport. UDP ports, for example, provide transport endpoints.

(*) RxRPC supports multiple virtual "connections" from any given transport
endpoint, thus allowing the endpoints to be shared, even to the same remote endpoint.

(*) Each connection goes to a particular "service". A connection may not go
to multiple services. A service may be considered the RxRPC equivalent of a port number. AF_RXRPC permits multiple services to share an endpoint.

(*) Client-originating packets are marked, thus a transport endpoint can be
shared between client and server connections (connections have a direction).

(*) Up to a billion connections may be supported concurrently between one
local transport endpoint and one service on one remote endpoint. An RxRPC connection is described by seven numbers:

Local address }
Local port } Transport (UDP) address
Remote address }
Remote port }
Direction
Connection ID
Service ID

(*) Each RxRPC operation is a "call". A connection may make up to four
billion calls, but only up to four calls may be in progress on a connection at any one time.

(*) Calls are two-phase and asymmetric: the client sends its request data,
which the service receives; then the service transmits the reply data which the client receives.

(*) The data blobs are of indefinite size, the end of a phase is marked with a
flag in the packet. The number of packets of data making up one blob may not exceed 4 billion, however, as this would cause the sequence number to wrap.

(*) The first four bytes of the request data are the service operation ID.

(*) Security is negotiated on a per-connection basis. The connection is
initiated by the first data packet on it arriving. If security is requested, the server then issues a "challenge" and then the client replies with a "response". If the response is successful, the security is set for the lifetime of that connection, and all subsequent calls made upon it use that same security. In the event that the server lets a connection lapse before the client, the security will be renegotiated if the client uses the connection again.

(*) Calls use ACK packets to handle reliability. Data packets are also
explicitly sequenced per call.

(*) There are two types of positive acknowledgement: hard-ACKs and soft-ACKs.
A hard-ACK indicates to the far side that all the data received to a point has been received and processed; a soft-ACK indicates that the data has been received but may yet be discarded and re-requested. The sender may not discard any transmittable packets until they've been hard-ACK'd.

(*) Reception of a reply data packet implicitly hard-ACK's all the data
packets that make up the request.

(*) An call is complete when the request has been sent, the reply has been
received and the final hard-ACK on the last packet of the reply has reached the server.

(*) An call may be aborted by either end at any time up to its completion.

=====================
AF_RXRPC DRIVER MODEL
=====================

About the AF_RXRPC driver:

(*) The AF_RXRPC protocol transparently uses internal sockets of the transport
protocol to represent transport endpoints.

(*) AF_RXRPC sockets map onto RxRPC connection bundles. Actual RxRPC
connections are handled transparently. One client socket may be used to make multiple simultaneous calls to the same service. One server socket may handle calls from many clients.

(*) Additional parallel client connections will be initiated to support extra
concurrent calls, up to a tunable limit.

(*) Each connection is retained for a certain amount of time [tunable] after
the last call currently using it has completed in case a new call is made that could reuse it.

(*) Each internal UDP socket is retained [tunable] for a certain amount of
time [tunable] after the last connection using it discarded, in case a new connection is made that could use it.

(*) A client-side connection is only shared between calls if they have have
the same key struct describing their security (and assuming the calls would otherwise share the connection). Non-secured calls would also be able to share connections with each other.

(*) ACK'ing is handled by the protocol driver automatically, including ping
replying.

(*) SO_KEEPALIVE automatically pings the other side to keep the connection
alive [TODO].

(*) If an ICMP error is received, all calls affected by that error will be
aborted with an appropriate network error passed through recvmsg().

Interaction with the user of the RxRPC socket:

(*) A socket is made into a server socket by binding an address with a
non-zero service ID [TODO].

(*) In the client, sending a request is achieved with one or more sendmsgs,
followed by the reply being received with one or more recvmsgs.

(*) The first sendmsg for a request to be sent from a client contains a tag to
be used in all other sendmsgs or recvmsgs associated with that call. The tag is carried in the control data.

(*) Once the client has received the last message associated with a call, the
tag is guaranteed not to be seen again, and so it can be used to pin client resources. A new call can then be initiated with the same tag without fear of interference.

(*) In the server, a request is received with one or more recvmsgs, then the
the reply is transmitted with one or more sendmsgs, and then the final ACK is received with a last recvmsg [TODO].

(*) When sending data, sendmsg is given MSG_MORE if there's more data to come.

(*) An abort may be issued by adding an control message to the control data.
Issuing an abort terminates the kernel's use of that call's tag.

(*) Aborts, busy notifications and challenge packets are collected by recvmsg
with control data message to indicate the context. Receiving an abort or a busy message terminates the kernel's use of that call's tag.

(*) The control data part of the msghdr struct is used for a number of things:

(*) The tag of the intended or affected call.

(*) Sending or receiving errors, aborts, busy notifications, challenge and
response notifications.

(*) Sending debug requests and receiving debug replies [TODO].

(*) The server application has to assist in the setting up of security. The
server sends a challenge packet to the client and receives a response packet [TODO].

(*) The name of the key a client will use to secure its communications is
nominated by a socket option.

========
SECURITY
========

Currently, only the kerberos 4 equivalent protocol has been implemented (security index 2 - rxkad). This requires the rxkad module to be loaded and, on the client, tickets of the appropriate type to be obtained from the AFS kaserver or the kerberos server and installed as "rxrpc" type keys. This is normally done using the klog program. An example simple klog program can be found at:

http://people.redhat.com/~dhowells/rxrpc/klog.c

The payload provided to add_key() on the client should be of the following form:

	struct rxrpc_key_sec2_v1 {
		uint16_t	security_index;	/* 2 */
		uint16_t	ticket_length;	/* length of ticket[] */
		uint32_t	expiry;		/* time at which expires */
		uint8_t		kvno;		/* key version number */
		uint8_t		__pad[3];
		uint8_t		session_key[8];	/* DES session key */
		uint8_t		ticket[0];	/* the encrypted ticket */
	};

Where the ticket blob is just appended to the above structure.

====================
EXAMPLE CLIENT USAGE
====================

A client would issue an operation by:

(1) An RxRPC socket is set up by:

client = socket(AF_RXRPC, SOCK_RPC, PF_INET);

Where the third parameter indicates the protocol family of the transport socket used - usually IPv4 but it can also be IPv6 [TODO].

(2) A local address can optionally be bound:

struct sockaddr_rxrpc srx = {
.srx_family = AF_RXRPC,
.srx_service = 0, /* we're a client */
.transport_type = SOCK_DGRAM, /* type of transport socket */
.transport.sin_family = AF_INET,
.transport.sin_port = htons(7000), /* AFS callback */
.transport.sin_address = 0, /* all local interfaces */
};
bind(client, &srx, sizeof(srx));

This specifies the local UDP port to be used. If not given, a random non-privileged port will be used. A UDP port may be shared between several unrelated RxRPC sockets. Security is handled on a basis of per-RxRPC virtual connection.

(3) The security is set:

	const char *key = "AFS:cambridge.redhat.com";
	setsockopt(client, SOL_RXRPC, RXRPC_SECURITY_KEY, key, strlen(key));

     This issues a request_key() to get the key representing the security
     context.  The minimum security level can be set:

	unsigned int sec = RXRPC_SECURITY_ENCRYPTED;
	setsockopt(client, SOL_RXRPC, RXRPC_MIN_SECURITY_LEVEL,
		   &sec, sizeof(sec));

(4) The server to be contacted is then specified:

	struct sockaddr_rxrpc srx = {
		.srx_family	= AF_RXRPC,
		.srx_service	= VL_SERVICE_ID,
		.transport_type	= SOCK_DGRAM,	/* type of transport socket */
		.transport.sin_family	= AF_INET,
		.transport.sin_port	= htons(7005), /* AFS volume manager */
		.transport.sin_address	= ...,
	};
	connect(client, &srx, sizeof(srx));

(5) The request is then sent:

	sendmsg(client, msg, 0);

(6) And the reply received:

	recvmsg(client, msg, 0);

     If an abort or error occurred, this will be returned in the control data
     buffer.

====================
EXAMPLE SERVER USAGE [PROPOSED]
====================

A server would accept operations by:

(1) An RxRPC socket would be set up by:

server = socket(AF_RXRPC, SOCK_RPC, PF_INET);

Where the third parameter indicates the address type of the transport socket used - usually IPv4.

(2) A local address would be bound:

	struct sockaddr_rxrpc srx = {
		.srx_family	= AF_RXRPC,
		.srx_service	= VL_SERVICE_ID, /* RxRPC service ID */
		.transport_type	= SOCK_DGRAM,	/* type of transport socket */
		.transport.sin_family	= AF_INET,
		.transport.sin_port	= htons(7000), /* AFS callback */
		.transport.sin_address	= 0,  /* all local interfaces */
	};
	bind(server, &srx, sizeof(srx));

(3) The server would then listen out for incoming calls:

	listen(server, 100);

(4) It would accept calls that were made:

	struct sockaddr_rxrpc srx;
	socken_t slen = sizeof(srx)
	call = accept(server, &src, &slen);

(5) The first data packet would then be received:

recvmsg(call, msg, 0);

A connection is discovered on the server by reception of the first data packet holding its connection ID. Only then can security be set up.

(6) The security context might need to be set up:

(a) The security index can be examined:

uint16_t sectype;
socklen_t len = sizeof(sectype);
getsockopt(call, SOL_RXRPC, RXRPC_GET_SECURITY_INDEX, &sectype, &len);

(b) A security challenge can be made:

sendmsg(call, msg, 0);

The control message will contain the challenge; there would be no data.

(c) And the security response received:

recvmsg(call, msg, 0);

The control message will contain the response; there would be no data.

(d) The security context can then be set:

setsockopt(call, SOL_RXRPC, RXRPC_SET_SECURITY, buffer, buflen);

If the virtual RxRPC connection already has security set up, the getsockopt will indicate this, and steps (b) to (d) can be skipped.

A security rejection would be achieved simply by closing the socket before step (d).

(7) The data could then be received:

	recvmsg(call, msg, 0);

(8) And then the reply transmitted:

sendmsg(client, msg, 0);

If an abort/error is to be served instead, that would be placed in the control data, and no data would be attached.

(9) Then the socket would be closed.

#1 lore raw

PATCH 1/5 Add PCBC crypto template support

Add PCBC crypto template support as used by RxRPC.

---

 crypto/Kconfig  |    9 +
 crypto/Makefile |    1 
 crypto/pcbc.c   |  348 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 358 insertions(+), 0 deletions(-)
crypto/Kconfig +9 -0
index 918b4d8..48996b7 100644
@@ -149,6 +149,15 @@ config CRYPTO_CBC
 	  CBC: Cipher Block Chaining mode
 	  This block cipher algorithm is required for IPSec.
 
+config CRYPTO_PCBC
+	tristate "PCBC support"
+	select CRYPTO_BLKCIPHER
+	select CRYPTO_MANAGER
+	default m
+	help
+	  PCBC: Propagating Cipher Block Chaining mode
+	  This block cipher algorithm is required for RxRPC.
+
 config CRYPTO_LRW
 	tristate "LRW support (EXPERIMENTAL)"
 	depends on EXPERIMENTAL
crypto/Makefile +1 -0
index 60e3d24..9ef048d 100644
@@ -27,6 +27,7 @@ obj-$(CONFIG_CRYPTO_TGR192) += tgr192.o
 obj-$(CONFIG_CRYPTO_GF128MUL) += gf128mul.o
 obj-$(CONFIG_CRYPTO_ECB) += ecb.o
 obj-$(CONFIG_CRYPTO_CBC) += cbc.o
+obj-$(CONFIG_CRYPTO_PCBC) += pcbc.o
 obj-$(CONFIG_CRYPTO_LRW) += lrw.o
 obj-$(CONFIG_CRYPTO_DES) += des.o
 obj-$(CONFIG_CRYPTO_BLOWFISH) += blowfish.o
crypto/pcbc.c new file +348 -0

348 lines not on this page · raw message

#2 lore raw

Re: [PATCH 1/5] Add PCBC crypto template support

Quoted 3 lines · David Howells

Add PCBC crypto template support as used by RxRPC.

This is already in the crypto-2.6 tree that I pushed yesterday.

Cheers,

Signature · 4 lines
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmV>HI~} <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
#3 lore raw

Re: [PATCH 1/5] Add PCBC crypto template support

Quoted 2 lines · Herbert Xu

This is already in the crypto-2.6 tree that I pushed yesterday.

Thanks. However, I'll continue to include the patches in my set until they reach Linus's tree.

David

maintainer
#4 lore raw

Re: [PATCH 1/5] Add PCBC crypto template support

From: David Howells <[email protected]>
Date: Fri, 09 Feb 2007 11:18:01 +0000

Quoted 7 lines
Quoted 2 lines · Herbert Xu

This is already in the crypto-2.6 tree that I pushed yesterday.

Thanks. However, I'll continue to include the patches in my set until they reach Linus's tree.

They are in Linus's tree.

#5 lore raw

Re: [PATCH 1/5] Add PCBC crypto template support

Quoted 4 lines · David Miller
Quoted 2 lines

Thanks. However, I'll continue to include the patches in my set until they reach Linus's tree.

They are in Linus's tree.

Yay!

#6 lore raw

PATCH 2/5 FCrypt encryption module

In reply to David Howells

Add a crypto module to provide FCrypt encryption as used by RxRPC.

---

 crypto/Kconfig  |    7 +
 crypto/Makefile |    1 
 crypto/fcrypt.c |  423 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 crypto/tcrypt.c |   16 ++
 crypto/tcrypt.h |  128 +++++++++++++++++
 5 files changed, 574 insertions(+), 1 deletions(-)
crypto/Kconfig +7 -0
index 48996b7..6d0d682 100644
@@ -177,6 +177,13 @@ config CRYPTO_DES
 	help
 	  DES cipher algorithm (FIPS 46-2), and Triple DES EDE (FIPS 46-3).
 
+config CRYPTO_FCRYPT
+	tristate "FCrypt cipher algorithm"
+	select CRYPTO_ALGAPI
+	select CRYPTO_BLKCIPHER
+	help
+	  FCrypt algorithm used by RxRPC.
+
 config CRYPTO_BLOWFISH
 	tristate "Blowfish cipher algorithm"
 	select CRYPTO_ALGAPI
crypto/Makefile +1 -0
index 9ef048d..a3e1915 100644
@@ -30,6 +30,7 @@ obj-$(CONFIG_CRYPTO_CBC) += cbc.o
 obj-$(CONFIG_CRYPTO_PCBC) += pcbc.o
 obj-$(CONFIG_CRYPTO_LRW) += lrw.o
 obj-$(CONFIG_CRYPTO_DES) += des.o
+obj-$(CONFIG_CRYPTO_FCRYPT) += fcrypt.o
 obj-$(CONFIG_CRYPTO_BLOWFISH) += blowfish.o
 obj-$(CONFIG_CRYPTO_TWOFISH) += twofish.o
 obj-$(CONFIG_CRYPTO_TWOFISH_COMMON) += twofish_common.o
crypto/fcrypt.c new file +423 -0

423 lines not on this page · raw message

crypto/tcrypt.c +15 -1
index d671e89..eef0516 100644
@@ -71,7 +71,8 @@ static char *check[] = {
 	"des", "md5", "des3_ede", "rot13", "sha1", "sha256", "blowfish",
 	"twofish", "serpent", "sha384", "sha512", "md4", "aes", "cast6",
 	"arc4", "michael_mic", "deflate", "crc32c", "tea", "xtea",
-	"khazad", "wp512", "wp384", "wp256", "tnepres", "xeta", NULL
+	"khazad", "wp512", "wp384", "wp256", "tnepres", "xeta",  "fcrypt",
+	NULL
 };
 
 static void hexdump(unsigned char *buf, unsigned int len)
@@ -964,6 +965,12 @@ static void do_test(void)
 		test_cipher("ecb(xeta)", DECRYPT, xeta_dec_tv_template,
 			    XETA_DEC_TEST_VECTORS);
 
+		//FCrypt
+		test_cipher("pcbc(fcrypt)", ENCRYPT, fcrypt_pcbc_enc_tv_template,
+			    FCRYPT_ENC_TEST_VECTORS);
+		test_cipher("pcbc(fcrypt)", DECRYPT, fcrypt_pcbc_dec_tv_template,
+			    FCRYPT_DEC_TEST_VECTORS);
+
 		test_hash("sha384", sha384_tv_template, SHA384_TEST_VECTORS);
 		test_hash("sha512", sha512_tv_template, SHA512_TEST_VECTORS);
 		test_hash("wp512", wp512_tv_template, WP512_TEST_VECTORS);
@@ -1177,6 +1184,13 @@ static void do_test(void)
 			    XETA_DEC_TEST_VECTORS);
 		break;
 
+	case 31:
+		test_cipher("pcbc(fcrypt)", ENCRYPT, fcrypt_pcbc_enc_tv_template,
+			    FCRYPT_ENC_TEST_VECTORS);
+		test_cipher("pcbc(fcrypt)", DECRYPT, fcrypt_pcbc_dec_tv_template,
+			    FCRYPT_DEC_TEST_VECTORS);
+		break;
+
 	case 100:
 		test_hash("hmac(md5)", hmac_md5_tv_template,
 			  HMAC_MD5_TEST_VECTORS);
crypto/tcrypt.h +128 -0

134 lines not on this page · raw message

#7 lore raw

Re: [PATCH 2/5] FCrypt encryption module

crypto/Kconfig config CRYPTO_DES · line 185

Quoted 6 lines · David Howells
crypto/Kconfig +6 -0
+config CRYPTO_FCRYPT
+	tristate "FCrypt cipher algorithm"
+	select CRYPTO_ALGAPI
+	select CRYPTO_BLKCIPHER
+	help
+	  FCrypt algorithm used by RxRPC.

this probably wants a litte more vebose description :)

#8 lore raw

PATCH 3/5 Crypto: Add blkcipher accessors for using kernel data directly

In reply to David Howells

Add blkcipher accessors for using kernel data directly without the use of scatter lists.

Also add a CRYPTO_ALG_DMA algorithm capability flag to permit or deny the use of DMA and hardware accelerators. A hardware accelerator may not be used to access any arbitrary piece of kernel memory lest it not be in a DMA'able region. Only software algorithms may do that.

If kernel data is going to be accessed directly, then CRYPTO_ALG_DMA must, for instance, be passed in the mask of crypto_alloc_blkcipher(), but not the type.

---

 crypto/blkcipher.c     |    2 ++
 crypto/pcbc.c          |   60 ++++++++++++++++++++++++++++++++++++++++++++++++
 include/linux/crypto.h |   52 +++++++++++++++++++++++++++++++++++++++++-
 3 files changed, 113 insertions(+), 1 deletions(-)
crypto/blkcipher.c +2 -0
index 6e93004..d43c22e 100644
@@ -371,6 +371,8 @@ static int crypto_init_blkcipher_ops(str
 	crt->setkey = setkey;
 	crt->encrypt = alg->encrypt;
 	crt->decrypt = alg->decrypt;
+	crt->encrypt_kernel = alg->encrypt_kernel;
+	crt->decrypt_kernel = alg->decrypt_kernel;
 
 	addr = (unsigned long)crypto_tfm_ctx(tfm);
 	addr = ALIGN(addr, align);
crypto/pcbc.c +60 -0

78 lines not on this page · raw message

include/linux/crypto.h +51 -1

88 lines not on this page · raw message

#9 lore raw

PATCH 4/5 Move generic skbuff stuff from XFRM code to generic code

In reply to David Howells

Move generic skbuff stuff from XFRM code to generic code so that AF_RXRPC can use it too.

---

 include/linux/skbuff.h |    4 +
 include/net/esp.h      |    2 -
 net/core/skbuff.c      |  173 ++++++++++++++++++++++++++++++++++++++++++++++++
 net/xfrm/xfrm_algo.c   |  169 -----------------------------------------------
 4 files changed, 177 insertions(+), 171 deletions(-)
include/linux/skbuff.h +4 -0
index 4ff3940..8701b12 100644
@@ -1481,5 +1481,9 @@ static inline int skb_is_gso(const struc
 	return skb_shinfo(skb)->gso_size;
 }
 
+struct scatterlist;
+extern int skb_to_sgvec(struct sk_buff *skb, struct scatterlist *sg, int offset, int len);
+extern int skb_cow_data(struct sk_buff *skb, int tailbits, struct sk_buff **trailer);
+
 #endif	/* __KERNEL__ */
 #endif	/* _LINUX_SKBUFF_H */
include/net/esp.h +0 -2
index 713d039..d05d8d2 100644
@@ -40,8 +40,6 @@ struct esp_data
 	} auth;
 };
 
-extern int skb_to_sgvec(struct sk_buff *skb, struct scatterlist *sg, int offset, int len);
-extern int skb_cow_data(struct sk_buff *skb, int tailbits, struct sk_buff **trailer);
 extern void *pskb_put(struct sk_buff *skb, struct sk_buff *tail, int len);
 
 static inline int esp_mac_digest(struct esp_data *esp, struct sk_buff *skb,
net/core/skbuff.c +173 -0

188 lines not on this page · raw message

net/xfrm/xfrm_algo.c +0 -169

175 lines not on this page · raw message

#10 lore raw
In reply to David Howells

In article <[email protected]> (at Thu, 08 Feb 2007 16:32:11 +0000), David Howells <[email protected]> says:

Quoted 10 lines

(2) A local address can optionally be bound:

	struct sockaddr_rxrpc srx = {
		.srx_family	= AF_RXRPC,
		.srx_service	= 0,  /* we're a client */
		.transport_type	= SOCK_DGRAM,	/* type of transport socket */
		.transport.sin_family	= AF_INET,
		.transport.sin_port	= htons(7000), /* AFS callback */
		.transport.sin_address	= 0,  /* all local interfaces */
	};

This sockaddr_rxrpc{} should NOT include sockaddr_in{} directly. Please use sockaddr_storage{} (or sockaddr{}, maybe), and make it sure to align on 64-bit word.

--yoshfuji

maintainer
#11 lore raw

From: YOSHIFUJI Hideaki <[email protected]>
Date: Fri, 09 Feb 2007 01:55:39 +0900 (JST)

Quoted 13 lines

In article <[email protected]> (at Thu, 08 Feb 2007 16:32:11 +0000), David Howells <[email protected]> says:

Quoted 10 lines

(2) A local address can optionally be bound:

	struct sockaddr_rxrpc srx = {
		.srx_family	= AF_RXRPC,
		.srx_service	= 0,  /* we're a client */
		.transport_type	= SOCK_DGRAM,	/* type of transport socket */
		.transport.sin_family	= AF_INET,
		.transport.sin_port	= htons(7000), /* AFS callback */
		.transport.sin_address	= 0,  /* all local interfaces */
	};
Quoted 3 lines

This sockaddr_rxrpc{} should NOT include sockaddr_in{} directly. Please use sockaddr_storage{} (or sockaddr{}, maybe), and make it sure to align on 64-bit word.

This is correct.

David, we should make the suggested changes in order to support IPv6 (and theoretically other address families as the transport) cleanly.

#12 lore raw
In reply to YOSHIFUJI Hideaki / 吉藤英明
Quoted 3 lines · YOSHIFUJI Hideaki

This sockaddr_rxrpc{} should NOT include sockaddr_in{} directly. Please use sockaddr_storage{} (or sockaddr{}, maybe), and make it sure to align on 64-bit word.

That won't work. That would then make the address larger than the maximum size (ie: sizeof(struct sockaddr_storage)).

David

#13 lore raw

In article <[email protected]> (at Fri, 09 Feb 2007 10:31:34 +0000), David Howells <[email protected]> says:

Quoted 8 lines
Quoted 3 lines · YOSHIFUJI Hideaki

This sockaddr_rxrpc{} should NOT include sockaddr_in{} directly. Please use sockaddr_storage{} (or sockaddr{}, maybe), and make it sure to align on 64-bit word.

That won't work. That would then make the address larger than the maximum size (ie: sizeof(struct sockaddr_storage)).

sockaddr{}, then...

--yoshfuji

#14 lore raw
In reply to YOSHIFUJI Hideaki / 吉藤英明
Quoted 1 line · YOSHIFUJI Hideaki

and make it sure to align on 64-bit word.

The first part of sockaddr_rxrpc is exactly 64 bits; then comes the transport address, so that's okay.

Quoted 2 lines

This sockaddr_rxrpc{} should NOT include sockaddr_in{} directly. Please use sockaddr_storage{} (or sockaddr{}, maybe),

Why can't I include sockaddr_in and sockaddr_in6 in sockaddr_rxrpc, btw?

Quoted 4 lines
Quoted 2 lines

That won't work. That would then make the address larger than the maximum size (ie: sizeof(struct sockaddr_storage)).

sockaddr{}, then...

But that's not big enough to hold a sockaddr_in6...

David

#15 lore raw

In article <[email protected]> (at Fri, 09 Feb 2007 12:31:23 +0000), David Howells <[email protected]> says:

Quoted 11 lines
Quoted 1 line · YOSHIFUJI Hideaki

and make it sure to align on 64-bit word.

The first part of sockaddr_rxrpc is exactly 64 bits; then comes the transport address, so that's okay.

Quoted 2 lines

This sockaddr_rxrpc{} should NOT include sockaddr_in{} directly. Please use sockaddr_storage{} (or sockaddr{}, maybe),

Why can't I include sockaddr_in and sockaddr_in6 in sockaddr_rxrpc, btw?

Because it is protocol (such as ipv4 or ipv6) dependent. You cannot use different sturcture for one address family. You could use union, maybe.

Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

That won't work. That would then make the address larger than the maximum size (ie: sizeof(struct sockaddr_storage)).

sockaddr{}, then...

But that's not big enough to hold a sockaddr_in6...

struct sockaddr_rxrpc {
...
union {
struct sockaddr rxrpc_sa;
struct sockaddr_in rxrpc_sin;
struct sockaddr_in6 rxrpc_sin6;
} __attribute__((__aligned(8)__));
};

Another option would be to introduce new transport protocol such as dccp or sctp, no?

--yoshfuji

#16 lore raw
Quoted 1 line · YOSHIFUJI Hideaki

Because it is protocol (such as ipv4 or ipv6) dependent.

Hmmm... I had thought of RxRPC being very transport dependent, being rather tied to UDPv4, though probably simply extensible to UDPv6. However, as long as the transport-layer header is removed on received packets before the main part of the code sees them, there shouldn't be any problem supporting non-UDP protocols, apart from, possibly, network error (ICMP) handling.

Some of the AFS operations, however, only deal in IPv4 addresses. I believe there is work afoot to deal with this, but I as far as I know it hasn't been dealt with yet.

Currently RxRPC is *only* available over UDPv4 in OpenAFS as far as I know.

Quoted 2 lines

You cannot use different sturcture for one address family. You could use union, maybe.

I am using a union:

	struct sockaddr_rxrpc {
		sa_family_t	srx_family;
		u16		srx_service;
		u16		transport_type;
		u16		transport_len;
		union {
			sa_family_t family;
			struct sockaddr_in sin;
			struct sockaddr_in6 sin6;
		} transport;
	};

I can add the alignment restrictor to the union though.

Quoted 2 lines

Another option would be to introduce new transport protocol such as dccp or sctp, no?

It's not my choice. My code must interoperate with the other RxRPC/AFS implementations that are already out there and have been around for many years.

David

#17 lore raw
In reply to YOSHIFUJI Hideaki / 吉藤英明
Quoted 3 lines · YOSHIFUJI Hideaki

This sockaddr_rxrpc{} should NOT include sockaddr_in{} directly. Please use sockaddr_storage{} (or sockaddr{}, maybe), and make it sure to align on 64-bit word.

How about this then:

struct sockaddr_rxrpc {
sa_family_t srx_family; /* address family */
u16 srx_service; /* service desired */
u16 transport_type; /* type of transport socket (SOCK_DGRAM) */
u16 transport_len; /* length of transport address */
struct sockaddr srx_sa[0]; /* address of transport endpoint */
};

Then whoever wants to use it must follow it immediately with an address of the appropriate type. The length given to connect or bind would then be the combined length of the two addresses.

Someone could then set one up on the stack by this sort of thing:

	int zebra(int fd)
	{
		struct {
			struct sockaddr_rxrpc srx;
			struct sockaddr_in sin;
		} sa;

		...
		if (connect(fd, (struct sockaddr *) &sa, sizeof(sa)) < 0)
			...
		...
	}

David