summaryrefslogtreecommitdiffstats
path: root/src/vcl/ldp.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/vcl/ldp.c')
-rw-r--r--src/vcl/ldp.c176
1 files changed, 83 insertions, 93 deletions
diff --git a/src/vcl/ldp.c b/src/vcl/ldp.c
index e806dff7959..beaa988185d 100644
--- a/src/vcl/ldp.c
+++ b/src/vcl/ldp.c
@@ -612,36 +612,35 @@ fcntl (int fd, int cmd, ...)
{
case F_SETFL:
func_str = "vppcom_session_attr[SET_FLAGS]";
- if (LDP_DEBUG > 2)
- clib_warning ("LDP<%d>: fd %d (0x%x): calling %s(): "
- "sid %u (0x%x) flags %d (0x%x), size %d",
- getpid (), fd, fd, func_str, sid, sid,
- flags, flags, size);
+ LDBG (2, "LDP<%d>: fd %d (0x%x): calling %s(): sid %u (0x%x) "
+ "flags %d (0x%x), size %d", getpid (), fd, fd, func_str, sid,
+ sid, flags, flags, size);
- rv =
- vppcom_session_attr (sid, VPPCOM_ATTR_SET_FLAGS, &flags, &size);
+ rv = vppcom_session_attr (sid, VPPCOM_ATTR_SET_FLAGS, &flags,
+ &size);
break;
case F_GETFL:
func_str = "vppcom_session_attr[GET_FLAGS]";
- if (LDP_DEBUG > 2)
- clib_warning
- ("LDP<%d>: fd %d (0x%x): calling %s(): sid %u (0x%x), "
- "flags %d (0x%x), size %d", getpid (), fd, fd, func_str, sid,
- sid, flags, flags, size);
+ LDBG (2, "LDP<%d>: fd %d (0x%x): calling %s(): sid %u (0x%x), "
+ "flags %d (0x%x), size %d", getpid (), fd, fd, func_str, sid,
+ sid, flags, flags, size);
- rv =
- vppcom_session_attr (sid, VPPCOM_ATTR_GET_FLAGS, &flags, &size);
+ rv = vppcom_session_attr (sid, VPPCOM_ATTR_GET_FLAGS, &flags,
+ &size);
if (rv == VPPCOM_OK)
{
- if (LDP_DEBUG > 2)
- clib_warning ("LDP<%d>: fd %d (0x%x), cmd %d (F_GETFL): "
- "%s() returned flags %d (0x%x)",
- getpid (), fd, fd, cmd, func_str, flags, flags);
+ LDBG (2, "LDP<%d>: fd %d (0x%x), cmd %d (F_GETFL): %s() "
+ "returned flags %d (0x%x)", getpid (), fd, fd, cmd,
+ func_str, flags, flags);
rv = flags;
}
break;
-
+ case F_SETFD:
+ /* TODO handle this */
+ LDBG (0, "F_SETFD ignored flags %u", flags);
+ rv = 0;
+ break;
default:
rv = -EOPNOTSUPP;
break;
@@ -800,9 +799,8 @@ ldp_pselect (int nfds, fd_set * __restrict readfds,
/* select as fine grained sleep */
if (!nfds)
{
- if (LDP_DEBUG > 3)
- clib_warning ("LDP<%d>: sleeping for %.02f seconds",
- getpid (), time_out);
+ LDBG (3, "LDP<%d>: sleeping for %.02f seconds", getpid (),
+ time_out);
time_out += clib_time_now (&ldp->clib_time);
while (clib_time_now (&ldp->clib_time) < time_out)
@@ -823,11 +821,9 @@ ldp_pselect (int nfds, fd_set * __restrict readfds,
{
func_str = "libc_pselect";
- if (LDP_DEBUG > 3)
- clib_warning
- ("LDP<%d>: calling %s(): nfds %d, readfds %p, writefds %p, "
- "exceptfds %p, timeout %p, sigmask %p", getpid (), func_str, nfds,
- readfds, writefds, exceptfds, timeout, sigmask);
+ LDBG (3, "LDP<%d>: calling %s(): nfds %d, readfds %p, writefds %p, "
+ "exceptfds %p, timeout %p, sigmask %p", getpid (), func_str, nfds,
+ readfds, writefds, exceptfds, timeout, sigmask);
rv = libc_pselect (nfds, readfds, writefds, exceptfds,
timeout, sigmask);
@@ -845,27 +841,27 @@ ldp_pselect (int nfds, fd_set * __restrict readfds,
}
sid_bits = libc_bits = 0;
+ u32 n_bytes = nfds / 8 + ((nfds % 8) ? 1 : 0);
if (readfds)
{
clib_bitmap_validate (ldp->sid_rd_bitmap, minbits);
clib_bitmap_validate (ldp->libc_rd_bitmap, minbits);
clib_bitmap_validate (ldp->rd_bitmap, minbits);
- clib_memcpy_fast (ldp->rd_bitmap, readfds,
- vec_len (ldp->rd_bitmap) * sizeof (clib_bitmap_t));
- FD_ZERO (readfds);
+ clib_memcpy_fast (ldp->rd_bitmap, readfds, n_bytes);
+ memset (readfds, 0, n_bytes);
/* *INDENT-OFF* */
- clib_bitmap_foreach (fd, ldp->rd_bitmap,
- ({
- sid = ldp_sid_from_fd (fd);
- if (LDP_DEBUG > 3)
- clib_warning ("LDP<%d>: readfds: fd %d (0x%x), sid %u (0x%x)",
- getpid (), fd, fd, sid, sid);
- if (sid == INVALID_SESSION_ID)
- clib_bitmap_set_no_check (ldp->libc_rd_bitmap, fd, 1);
- else
- clib_bitmap_set_no_check (ldp->sid_rd_bitmap, sid, 1);
- }));
+ clib_bitmap_foreach (fd, ldp->rd_bitmap, ({
+ if (fd > nfds)
+ break;
+ sid = ldp_sid_from_fd (fd);
+ LDBG (3, "LDP<%d>: readfds: fd %d (0x%x), sid %u (0x%x)",
+ getpid (), fd, fd, sid, sid);
+ if (sid == INVALID_SESSION_ID)
+ clib_bitmap_set_no_check (ldp->libc_rd_bitmap, fd, 1);
+ else
+ clib_bitmap_set_no_check (ldp->sid_rd_bitmap, sid, 1);
+ }));
/* *INDENT-ON* */
sid_bits_set = clib_bitmap_last_set (ldp->sid_rd_bitmap) + 1;
@@ -874,32 +870,30 @@ ldp_pselect (int nfds, fd_set * __restrict readfds,
libc_bits_set = clib_bitmap_last_set (ldp->libc_rd_bitmap) + 1;
libc_bits = (libc_bits_set > libc_bits) ? libc_bits_set : libc_bits;
- if (LDP_DEBUG > 3)
- clib_warning ("LDP<%d>: readfds: sid_bits_set %d, sid_bits %d, "
- "libc_bits_set %d, libc_bits %d", getpid (),
- sid_bits_set, sid_bits, libc_bits_set, libc_bits);
+ LDBG (3, "LDP<%d>: readfds: sid_bits_set %d, sid_bits %d, "
+ "libc_bits_set %d, libc_bits %d", getpid (), sid_bits_set,
+ sid_bits, libc_bits_set, libc_bits);
}
if (writefds)
{
clib_bitmap_validate (ldp->sid_wr_bitmap, minbits);
clib_bitmap_validate (ldp->libc_wr_bitmap, minbits);
clib_bitmap_validate (ldp->wr_bitmap, minbits);
- clib_memcpy_fast (ldp->wr_bitmap, writefds,
- vec_len (ldp->wr_bitmap) * sizeof (clib_bitmap_t));
- FD_ZERO (writefds);
+ clib_memcpy_fast (ldp->wr_bitmap, writefds, n_bytes);
+ memset (writefds, 0, n_bytes);
/* *INDENT-OFF* */
- clib_bitmap_foreach (fd, ldp->wr_bitmap,
- ({
- sid = ldp_sid_from_fd (fd);
- if (LDP_DEBUG > 3)
- clib_warning ("LDP<%d>: writefds: fd %d (0x%x), sid %u (0x%x)",
- getpid (), fd, fd, sid, sid);
- if (sid == INVALID_SESSION_ID)
- clib_bitmap_set_no_check (ldp->libc_wr_bitmap, fd, 1);
- else
- clib_bitmap_set_no_check (ldp->sid_wr_bitmap, sid, 1);
- }));
+ clib_bitmap_foreach (fd, ldp->wr_bitmap, ({
+ if (fd > nfds)
+ break;
+ sid = ldp_sid_from_fd (fd);
+ LDBG (3, "LDP<%d>: writefds: fd %d (0x%x), sid %u (0x%x)",
+ getpid (), fd, fd, sid, sid);
+ if (sid == INVALID_SESSION_ID)
+ clib_bitmap_set_no_check (ldp->libc_wr_bitmap, fd, 1);
+ else
+ clib_bitmap_set_no_check (ldp->sid_wr_bitmap, sid, 1);
+ }));
/* *INDENT-ON* */
sid_bits_set = clib_bitmap_last_set (ldp->sid_wr_bitmap) + 1;
@@ -908,32 +902,30 @@ ldp_pselect (int nfds, fd_set * __restrict readfds,
libc_bits_set = clib_bitmap_last_set (ldp->libc_wr_bitmap) + 1;
libc_bits = (libc_bits_set > libc_bits) ? libc_bits_set : libc_bits;
- if (LDP_DEBUG > 3)
- clib_warning ("LDP<%d>: writefds: sid_bits_set %d, sid_bits %d, "
- "libc_bits_set %d, libc_bits %d", getpid (),
- sid_bits_set, sid_bits, libc_bits_set, libc_bits);
+ LDBG (3, "LDP<%d>: writefds: sid_bits_set %d, sid_bits %d, "
+ "libc_bits_set %d, libc_bits %d", getpid (),
+ sid_bits_set, sid_bits, libc_bits_set, libc_bits);
}
if (exceptfds)
{
clib_bitmap_validate (ldp->sid_ex_bitmap, minbits);
clib_bitmap_validate (ldp->libc_ex_bitmap, minbits);
clib_bitmap_validate (ldp->ex_bitmap, minbits);
- clib_memcpy_fast (ldp->ex_bitmap, exceptfds,
- vec_len (ldp->ex_bitmap) * sizeof (clib_bitmap_t));
- FD_ZERO (exceptfds);
+ clib_memcpy_fast (ldp->ex_bitmap, exceptfds, n_bytes);
+ memset (exceptfds, 0, n_bytes);
/* *INDENT-OFF* */
- clib_bitmap_foreach (fd, ldp->ex_bitmap,
- ({
- sid = ldp_sid_from_fd (fd);
- if (LDP_DEBUG > 3)
- clib_warning ("LDP<%d>: exceptfds: fd %d (0x%x), sid %u (0x%x)",
- getpid (), fd, fd, sid, sid);
- if (sid == INVALID_SESSION_ID)
- clib_bitmap_set_no_check (ldp->libc_ex_bitmap, fd, 1);
- else
- clib_bitmap_set_no_check (ldp->sid_ex_bitmap, sid, 1);
- }));
+ clib_bitmap_foreach (fd, ldp->ex_bitmap, ({
+ if (fd > nfds)
+ break;
+ sid = ldp_sid_from_fd (fd);
+ LDBG (3, "LDP<%d>: exceptfds: fd %d (0x%x), sid %u (0x%x)",
+ getpid (), fd, fd, sid, sid);
+ if (sid == INVALID_SESSION_ID)
+ clib_bitmap_set_no_check (ldp->libc_ex_bitmap, fd, 1);
+ else
+ clib_bitmap_set_no_check (ldp->sid_ex_bitmap, sid, 1);
+ }));
/* *INDENT-ON* */
sid_bits_set = clib_bitmap_last_set (ldp->sid_ex_bitmap) + 1;
@@ -942,10 +934,9 @@ ldp_pselect (int nfds, fd_set * __restrict readfds,
libc_bits_set = clib_bitmap_last_set (ldp->libc_ex_bitmap) + 1;
libc_bits = (libc_bits_set > libc_bits) ? libc_bits_set : libc_bits;
- if (LDP_DEBUG > 3)
- clib_warning ("LDP<%d>: exceptfds: sid_bits_set %d, sid_bits %d, "
- "libc_bits_set %d, libc_bits %d", getpid (),
- sid_bits_set, sid_bits, libc_bits_set, libc_bits);
+ LDBG (3, "LDP<%d>: exceptfds: sid_bits_set %d, sid_bits %d, "
+ "libc_bits_set %d, libc_bits %d", getpid (),
+ sid_bits_set, sid_bits, libc_bits_set, libc_bits);
}
if (PREDICT_FALSE (!sid_bits && !libc_bits))
@@ -1074,15 +1065,15 @@ ldp_pselect (int nfds, fd_set * __restrict readfds,
done:
/* TBD: set timeout to amount of time left */
- vec_reset_length (ldp->rd_bitmap);
- vec_reset_length (ldp->sid_rd_bitmap);
- vec_reset_length (ldp->libc_rd_bitmap);
- vec_reset_length (ldp->wr_bitmap);
- vec_reset_length (ldp->sid_wr_bitmap);
- vec_reset_length (ldp->libc_wr_bitmap);
- vec_reset_length (ldp->ex_bitmap);
- vec_reset_length (ldp->sid_ex_bitmap);
- vec_reset_length (ldp->libc_ex_bitmap);
+ clib_bitmap_zero (ldp->rd_bitmap);
+ clib_bitmap_zero (ldp->sid_rd_bitmap);
+ clib_bitmap_zero (ldp->libc_rd_bitmap);
+ clib_bitmap_zero (ldp->wr_bitmap);
+ clib_bitmap_zero (ldp->sid_wr_bitmap);
+ clib_bitmap_zero (ldp->libc_wr_bitmap);
+ clib_bitmap_zero (ldp->ex_bitmap);
+ clib_bitmap_zero (ldp->sid_ex_bitmap);
+ clib_bitmap_zero (ldp->libc_ex_bitmap);
if (LDP_DEBUG > 3)
{
@@ -1227,10 +1218,9 @@ socketpair (int domain, int type, int protocol, int fds[2])
{
func_str = "libc_socket";
- if (LDP_DEBUG > 1)
- clib_warning ("LDP<%d>: : calling %s()", getpid (), func_str);
+ LDBG (1, "LDP<%d>: : calling %s()", getpid (), func_str);
- rv = libc_socket (domain, type, protocol);
+ rv = libc_socketpair (domain, type, protocol, fds);
}
if (LDP_DEBUG > 1)
uot;: data, "is_hex": is_hex} def add_local_id(self, id_type, data): if isinstance(id_type, str): t = IDType.value(id_type) self.local_id = {"id_type": t, "data": data, "is_local": True} def add_remote_id(self, id_type, data): if isinstance(id_type, str): t = IDType.value(id_type) self.remote_id = {"id_type": t, "data": data, "is_local": False} def add_local_ts( self, start_addr, end_addr, start_port=0, end_port=0xFFFF, proto=0, is_ip4=True ): self.ts_is_ip4 = is_ip4 self.local_ts = { "is_local": True, "protocol_id": proto, "start_port": start_port, "end_port": end_port, "start_addr": start_addr, "end_addr": end_addr, } def add_remote_ts( self, start_addr, end_addr, start_port=0, end_port=0xFFFF, proto=0 ): try: IPv4Address(start_addr) is_ip4 = True except AddressValueError: is_ip4 = False self.ts_is_ip4 = is_ip4 self.remote_ts = { "is_local": False, "protocol_id": proto, "start_port": start_port, "end_port": end_port, "start_addr": start_addr, "end_addr": end_addr, } def add_responder_hostname(self, hn): self.responder_hostname = hn def add_responder(self, responder): self.responder = responder def add_ike_transforms(self, tr): self.ike_transforms = tr def add_esp_transforms(self, tr): self.esp_transforms = tr def set_udp_encap(self, udp_encap): self.udp_encap = udp_encap def set_lifetime_data(self, data): self.lifetime_data = data def set_ipsec_over_udp_port(self, port): self.ipsec_udp_port = {"is_set": 1, "port": port} def set_tunnel_interface(self, sw_if_index): self.tun_itf = sw_if_index def object_id(self): return "ikev2-profile-%s" % self.profile_name def remove_vpp_config(self): self.vapi.ikev2_profile_add_del(name=self.profile_name, is_add=False) def add_vpp_config(self): self.vapi.ikev2_profile_add_del(name=self.profile_name, is_add=True) if hasattr(self, "auth"): self.vapi.ikev2_profile_set_auth( name=self.profile_name, data_len=len(self.auth["data"]), **self.auth ) if hasattr(self, "local_id"): self.vapi.ikev2_profile_set_id( name=self.profile_name, data_len=len(self.local_id["data"]), **self.local_id, ) if hasattr(self, "remote_id"): self.vapi.ikev2_profile_set_id( name=self.profile_name, data_len=len(self.remote_id["data"]), **self.remote_id, ) if hasattr(self, "local_ts"): self.vapi.ikev2_profile_set_ts(name=self.profile_name, ts=self.local_ts) if hasattr(self, "remote_ts"): self.vapi.ikev2_profile_set_ts(name=self.profile_name, ts=self.remote_ts) if hasattr(self, "responder"): self.vapi.ikev2_set_responder( name=self.profile_name, responder=self.responder ) if hasattr(self, "responder_hostname"): print(self.responder_hostname) self.vapi.ikev2_set_responder_hostname( name=self.profile_name, **self.responder_hostname ) if hasattr(self, "ike_transforms"): self.vapi.ikev2_set_ike_transforms( name=self.profile_name, tr=self.ike_transforms ) if hasattr(self, "esp_transforms"): self.vapi.ikev2_set_esp_transforms( name=self.profile_name, tr=self.esp_transforms ) if self.udp_encap: self.vapi.ikev2_profile_set_udp_encap(name=self.profile_name) if hasattr(self, "lifetime_data"): self.vapi.ikev2_set_sa_lifetime( name=self.profile_name, **self.lifetime_data ) if hasattr(self, "ipsec_udp_port"): self.vapi.ikev2_profile_set_ipsec_udp_port( name=self.profile_name, **self.ipsec_udp_port ) if hasattr(self, "tun_itf"): self.vapi.ikev2_set_tunnel_interface( name=self.profile_name, sw_if_index=self.tun_itf ) if not self.natt: self.vapi.ikev2_profile_disable_natt(name=self.profile_name) def query_vpp_config(self): res = self.vapi.ikev2_profile_dump() for r in res: if r.profile.name == self.profile_name: return r.profile return None