caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: David Allsopp <dra-news@metastack.com>
To: "caml-list@inria.fr" <caml-list@inria.fr>
Subject: RE: [Caml-list] IPv6 zone-id
Date: Thu, 17 Jul 2014 10:51:47 +0000	[thread overview]
Message-ID: <E51C5B015DBD1348A1D85763337FB6D9E9154564@Remus.metastack.local> (raw)
In-Reply-To: <53C79BE0.7000605@luminar.eu.org>

Vincent B. wrote:
> On 16/07/2014 18:04, Francis Dupont wrote:
> > => I disagree: the zone-id is a member of the address, not an extra to
> > system calls using addresses.
> >
> > Regards
> 
> Agreed. My new proposition: make "type sockaddr" include flow_info and
> scope_id/zone_id
> 
> This would break existing code.

Two thoughts (one pure, one rather evil) on mechanisms which might not break existing code:

Given that the type inet_addr is abstract, and changing ADDR_INET is not desirable, a pure "trick" to maintain compatibility could be done with the type of inet_addr in Unix.ml where instead of being string it becomes string * int option * int option or something like that.

You can then add an extra function, ipv6_sockaddr with type inet_addr * int * int * int such that [ipv6_sockaddr address port flow scope] returns [ADDR_INET((#1 address, Some flow, Some scope), port)] and some kind of helper function ipv6_getsockaddr : sockaddr -> string * int option * int option.

That prevents existing code which expects ADDR_INET to have two values only from breaking but it does now mean that two inet_addr values will be non-equal based on a socket parameter which isn't great.

Another "solution" is to sacrifice one's soul on the altar of backwards compatibility and invoke Obj! Along the lines of:

type sockaddr = ...

type sockaddr_internal =
  ADDR_UNIX_INT of string
| ADDR_INET_INT of inet_addr * int * int * int

and then ipv6_sockaddr is defined as follows:

let ipv6_sockaddr inet_addr port flow scope =
  if domain_of_sockaddr inet_addr <> PF_INET6
  then invalid_arg "Unix.ipv6_sockaddr"
  else if flow = 0 && scope = 0
       then ADDR_INET(inet_addr, port)
       else (Obj.magic (ADDR_INET_INT(inet_addr, port, flow, scope)) : sockaddr)

let ipv6_getsockaddr sockaddr =
  match sockaddr with
    ADDR_INET(addr, port) ->
      if is_inet6_addr addr
      then if Obj.size (Obj.repr sockaddr) = 2
           then (addr, port, 0, 0)
           else let (addr, port, flow, scope) = (Obj.magic sockaddr : (inet_addr * int * int * int))
                in
                  (addr, port, flow, scope) 
     else invalid_arg "Unix.ipv6_getsockaddr"
  | _ ->
    invalid_arg "Unix.ipv6_getsockaddr"

Now you have a sockaddr type where differing flow and scope values will result in different sockaddr values (= good). The only thing (I think!) which this breaks, is C code which tests the block size of an ADDR_INET value instead of its tag... but that's a really odd thing to do. Obviously, a different runtime would also suffer - but the whole of Unix has to be rewritten for a different runtime anyway (JavaScript, HVLM, etc.) so that's maybe not so much of an issue.

The only weirdness is then needing a function to break apart the IPv6 parameters, but that seems to be unavoidable if your aim is backwards compatibility.

I should probably take a shower after writing that code, though...


David

      reply	other threads:[~2014-07-17 10:51 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-07-09 17:35 Vincent B.
2014-07-11  8:03 ` Raphaël Proust
2014-07-11 14:13   ` Vincent B.
2014-07-11 19:25     ` Vincent B.
2014-07-16 16:04       ` Francis Dupont
2014-07-17  9:48         ` Vincent B.
2014-07-17 10:51           ` David Allsopp [this message]

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=E51C5B015DBD1348A1D85763337FB6D9E9154564@Remus.metastack.local \
    --to=dra-news@metastack.com \
    --cc=caml-list@inria.fr \
    /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).