func executeUrl(command *client.SegmentCommand, seg *Segment) error { ci := &seg.Head if command.Tail { ci = &seg.Tail } proto, ns, hostname, port, err := utils.ParseUrl(command.Arg) if err != nil { return err } if proto != "" { ci.Proto = proto } if ns != "" { var err error ci.Ns, err = netns.GetFromName(ns) if err != nil { return err } } if hostname != "" { ci.Hostname = hostname } if port != 0 { ci.Port = port } return nil }
func parseUrl(tail bool, args *[]string) *client.SegmentCommand { if len(*args) == 0 { createFail("Argument URL is required for url") } url := (*args)[0] proto, _, _, _, err := utils.ParseUrl(url) if err != nil { createFail(fmt.Sprintf("Unable to parse URL: %v", url)) } if proto != "" && proto != "tcp" && proto != "udp" { createFail("Only tcp and udp protocols are currently supported.") } *args = (*args)[1:] return &client.SegmentCommand{Type: client.URL, Tail: tail, Arg: url} }
func executeTunnel(command *client.SegmentCommand, seg *Segment, udp bool) error { _, dst, err := createTunnel(command.Arg, udp) if err != nil { return err } urlCommand := client.SegmentCommand{Type: client.URL, Arg: dst.String()} command.ChildInit = append(command.ChildInit, urlCommand) c, err := client.NewClient(command.Arg, opts.config) if err != nil { return err } id := utils.Uuid() url, err := c.CreateSegment(id, command.ChildInit, command.ChildTrig) if err != nil { return err } seg.Tail.Proto, _, seg.Tail.Hostname, seg.Tail.Port, err = utils.ParseUrl(url) if err != nil { return err } seg.ChildHost = command.Arg seg.ChildId = id return nil }