mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-06 10:43:56 +00:00
agnhost/connect: send and recv data from SCTP server
If the client immediately closes connection after SCTP handshake, the server will die with EOF, adding send and recv calls in the client to make sure server client handling loop exits gracefully. Signed-off-by: Daman Arora <aroradaman@gmail.com>
This commit is contained in:
parent
8cf4567f3c
commit
1c8799f814
@ -47,12 +47,14 @@ var (
|
|||||||
timeout time.Duration
|
timeout time.Duration
|
||||||
protocol string
|
protocol string
|
||||||
udpData string
|
udpData string
|
||||||
|
sctpData string
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
CmdConnect.Flags().DurationVar(&timeout, "timeout", time.Duration(0), "Maximum time before returning an error")
|
CmdConnect.Flags().DurationVar(&timeout, "timeout", time.Duration(0), "Maximum time before returning an error")
|
||||||
CmdConnect.Flags().StringVar(&protocol, "protocol", "tcp", "The protocol to use to perform the connection, can be tcp, udp or sctp")
|
CmdConnect.Flags().StringVar(&protocol, "protocol", "tcp", "The protocol to use to perform the connection, can be tcp, udp or sctp")
|
||||||
CmdConnect.Flags().StringVar(&udpData, "udp-data", "hostname", "The UDP payload send to the server")
|
CmdConnect.Flags().StringVar(&udpData, "udp-data", "hostname", "The UDP payload send to the server")
|
||||||
|
CmdConnect.Flags().StringVar(&sctpData, "sctp-data", "hostname", "The SCTP payload send to the server")
|
||||||
}
|
}
|
||||||
|
|
||||||
func main(cmd *cobra.Command, args []string) {
|
func main(cmd *cobra.Command, args []string) {
|
||||||
@ -63,7 +65,7 @@ func main(cmd *cobra.Command, args []string) {
|
|||||||
case "udp":
|
case "udp":
|
||||||
connectUDP(dest, timeout, udpData)
|
connectUDP(dest, timeout, udpData)
|
||||||
case "sctp":
|
case "sctp":
|
||||||
connectSCTP(dest, timeout)
|
connectSCTP(dest, timeout, sctpData)
|
||||||
default:
|
default:
|
||||||
fmt.Fprint(os.Stderr, "Unsupported protocol\n", protocol)
|
fmt.Fprint(os.Stderr, "Unsupported protocol\n", protocol)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
@ -103,7 +105,11 @@ func connectTCP(dest string, timeout time.Duration) {
|
|||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
func connectSCTP(dest string, timeout time.Duration) {
|
func connectSCTP(dest string, timeout time.Duration, data string) {
|
||||||
|
var (
|
||||||
|
buf = make([]byte, 1024)
|
||||||
|
conn *sctp.SCTPConn
|
||||||
|
)
|
||||||
addr, err := sctp.ResolveSCTPAddr("sctp", dest)
|
addr, err := sctp.ResolveSCTPAddr("sctp", dest)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintf(os.Stderr, "DNS: %v\n", err)
|
fmt.Fprintf(os.Stderr, "DNS: %v\n", err)
|
||||||
@ -114,11 +120,24 @@ func connectSCTP(dest string, timeout time.Duration) {
|
|||||||
errCh := make(chan error)
|
errCh := make(chan error)
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
conn, err := sctp.DialSCTP("sctp", nil, addr)
|
conn, err = sctp.DialSCTP("sctp", nil, addr)
|
||||||
if err == nil {
|
if err != nil {
|
||||||
conn.Close()
|
errCh <- err
|
||||||
|
return
|
||||||
|
}
|
||||||
|
defer func() {
|
||||||
|
errCh <- conn.Close()
|
||||||
|
}()
|
||||||
|
|
||||||
|
if _, err = conn.Write([]byte(fmt.Sprintf("%s\n", data))); err != nil {
|
||||||
|
errCh <- err
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, err = conn.Read(buf); err != nil {
|
||||||
|
errCh <- err
|
||||||
|
return
|
||||||
}
|
}
|
||||||
errCh <- err
|
|
||||||
}()
|
}()
|
||||||
|
|
||||||
select {
|
select {
|
||||||
|
Loading…
Reference in New Issue
Block a user