Commit 08b3a24d authored by Ondrej Zajicek (work)'s avatar Ondrej Zajicek (work)
Browse files

IO: Minor changes in socket AF handing

AF can be specified implicitly by saddr or daddr, flags SKF_V4ONLY and
SKF_V6ONLY are to be removed.
parent 5af7b596
Loading
Loading
Loading
Loading
+25 −21
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@ typedef struct birdsock {
  resource r;
  pool *pool;				/* Pool where incoming connections should be allocated (for SK_xxx_PASSIVE) */
  int type;				/* Socket type */
  int subtype;				/* Socket subtype */
  void *data;				/* User data */
  ip_addr saddr, daddr;			/* IPA_NONE = unspecified */
  uint sport, dport;			/* 0 = unspecified (for IP: protocol type) */
@@ -44,7 +45,7 @@ typedef struct birdsock {
  uint lifindex;			/* local interface that received the datagram */
  /* laddr and lifindex are valid only if SKF_LADDR_RX flag is set to request it */

  int fam;				/* Address family (SK_FAM_* or 0 for non-IP) of fd */
  int af;				/* System-dependend adress family (e.g. AF_INET) */
  int fd;				/* System-dependent data */
  int index;				/* Index in poll buffer */
  int rcv_ttl;				/* TTL of last received datagram */
@@ -91,7 +92,6 @@ extern int sk_priority_control; /* Suggested priority for control traffic, shou

/* Socket flags */

#define SKF_V4ONLY	0x01	/* Use IPv4 for IP sockets */
#define SKF_V6ONLY	0x02	/* Use IPV6_V6ONLY socket option */
#define SKF_LADDR_RX	0x04	/* Report local address for RX packets */
#define SKF_TTL_RX	0x08	/* Report TTL / Hop Limit for RX packets */
@@ -116,31 +116,35 @@ extern int sk_priority_control; /* Suggested priority for control traffic, shou
#define SK_UNIX_PASSIVE	8
#define SK_UNIX		9

/* Socket families */
/*
 *	Socket subtypes
 */

#define SK_FAM_NONE	0
#define SK_FAM_IPV4	4
#define SK_FAM_IPV6	6
#define SK_IPV4		1
#define SK_IPV6		2

/*
 *  For SK_UDP or SK_IP sockets setting DA/DP allows to use sk_send(),
 *  otherwise sk_send_to() must be used.
 * For TCP/IP sockets, Address family (IPv4 or IPv6) can be specified either
 * explicitly (SK_IPV4 or SK_IPV6) or implicitly (based on saddr, daddr). But
 * these specifications must be consistent.
 *
 * For SK_UDP or SK_IP sockets setting DA/DP allows to use sk_send(), otherwise
 * sk_send_to() must be used.
 *
 *  For SK_IP sockets setting DP specifies protocol number, which is used
 *  for both receiving and sending.
 * For SK_IP sockets setting DP specifies protocol number, which is used for
 * both receiving and sending.
 *
 *  For multicast on SK_UDP or SK_IP sockets set IF and TTL,
 *  call sk_setup_multicast() to enable multicast on that socket,
 *  and then use sk_join_group() and sk_leave_group() to manage
 *  a set of received multicast groups.
 * For multicast on SK_UDP or SK_IP sockets set IF and TTL, call
 * sk_setup_multicast() to enable multicast on that socket, and then use
 * sk_join_group() and sk_leave_group() to manage a set of received multicast
 * groups.
 *
 *  For datagram (SK_UDP, SK_IP) sockets, there are two ways to handle
 *  source address. The socket could be bound to it using bind()
 *  syscall, but that also forbids the reception of multicast packets,
 *  or the address could be set on per-packet basis using platform
 *  dependent options (but these are not available in some corner
 *  cases). The first way is used when SKF_BIND is specified, the
 *  second way is used otherwise.
 * For datagram (SK_UDP, SK_IP) sockets, there are two ways to handle source
 * address. The socket could be bound to it using bind() syscall, but that also
 * forbids the reception of multicast packets, or the address could be set on
 * per-packet basis using platform dependent options (but these are not
 * available in some corner cases). The first way is used when SKF_BIND is
 * specified, the second way is used otherwise.
 */

#endif
+4 −4
Original line number Diff line number Diff line
@@ -981,10 +981,10 @@ bfd_start(struct proto *P)
  add_tail(&bfd_proto_list, &p->bfd_node);

  birdloop_enter(p->loop);
  p->rx4_1 = bfd_open_rx_sk(p, 0, 4);
  p->rx4_m = bfd_open_rx_sk(p, 1, 4);
  p->rx6_1 = bfd_open_rx_sk(p, 0, 6);
  p->rx6_m = bfd_open_rx_sk(p, 1, 6);
  p->rx4_1 = bfd_open_rx_sk(p, 0, SK_IPV4);
  p->rx4_m = bfd_open_rx_sk(p, 1, SK_IPV4);
  p->rx6_1 = bfd_open_rx_sk(p, 0, SK_IPV6);
  p->rx6_m = bfd_open_rx_sk(p, 1, SK_IPV6);
  birdloop_leave(p->loop);

  bfd_take_requests(p);
+2 −22
Original line number Diff line number Diff line
@@ -186,10 +186,11 @@ bfd_err_hook(sock *sk, int err)
}

sock *
bfd_open_rx_sk(struct bfd_proto *p, int multihop, int inet_version)
bfd_open_rx_sk(struct bfd_proto *p, int multihop, int af)
{
  sock *sk = sk_new(p->tpool);
  sk->type = SK_UDP;
  sk->subtype = af;
  sk->sport = !multihop ? BFD_CONTROL_PORT : BFD_MULTI_CTL_PORT;
  sk->data = p;

@@ -202,19 +203,6 @@ bfd_open_rx_sk(struct bfd_proto *p, int multihop, int inet_version)
  sk->priority = sk_priority_control;
  sk->flags = SKF_THREAD | SKF_LADDR_RX | (!multihop ? SKF_TTL_RX : 0);

  switch (inet_version) {
    case 4:
      sk->fam = SK_FAM_IPV4;
      sk->flags |= SKF_V4ONLY;
      break;
    case 6:
      sk->fam = SK_FAM_IPV6;
      sk->flags |= SKF_V6ONLY;
      break;
    default:
      ASSERT(0);
  }

  if (sk_open(sk) < 0)
    goto err;

@@ -246,14 +234,6 @@ bfd_open_tx_sk(struct bfd_proto *p, ip_addr local, struct iface *ifa)
  sk->ttl = ifa ? 255 : -1;
  sk->flags = SKF_THREAD | SKF_BIND | SKF_HIGH_PORT;

  if (ipa_is_ip4(local)) {
    sk->fam = SK_FAM_IPV4;
    sk->flags |= SKF_V4ONLY;
  } else {
    sk->fam = SK_FAM_IPV6;
    sk->flags |= SKF_V6ONLY;
  }

  if (sk_open(sk) < 0)
    goto err;

+2 −2
Original line number Diff line number Diff line
@@ -108,10 +108,10 @@ ospf_sk_open(struct ospf_iface *ifa)

  sock *sk = sk_new(ifa->pool);
  sk->type = SK_IP;
  sk->subtype = ospf_is_v2(p) ? SK_IPV4 : SK_IPV6;
  sk->dport = OSPF_PROTO;
  sk->saddr = ifa->addr->ip;
  sk->iface = ifa->iface;
  sk->fam = ospf_is_v2(p) ? SK_FAM_IPV4 : SK_FAM_IPV6;

  sk->tos = ifa->cf->tx_tos;
  sk->priority = ifa->cf->tx_priority;
@@ -193,8 +193,8 @@ ospf_open_vlink_sk(struct ospf_proto *p)
{
  sock *sk = sk_new(p->p.pool);
  sk->type = SK_IP;
  sk->subtype = ospf_is_v2(p) ? SK_IPV4 : SK_IPV6;
  sk->dport = OSPF_PROTO;
  sk->fam = ospf_is_v2(p) ? SK_FAM_IPV4 : SK_FAM_IPV6;

  /* FIXME: configurable tos/priority ? */
  sk->tos = IP_PREC_INTERNET_CONTROL;
+1 −1
Original line number Diff line number Diff line
@@ -410,9 +410,9 @@ radv_sk_open(struct radv_iface *ifa)
{
  sock *sk = sk_new(ifa->ra->p.pool);
  sk->type = SK_IP;
  sk->subtype = SK_IPV6;
  sk->dport = ICMPV6_PROTO;
  sk->saddr = ifa->addr->ip;
  sk->fam = SK_FAM_IPV6;

  sk->ttl = 255; /* Mandatory for Neighbor Discovery packets */
  sk->rx_hook = radv_rx_hook;
Loading