loadPortFile loads the provided port file. It returns a list of TCP and UDP ports to forward. The format of the file is tcp:port_number or udp:port_number on individual lines. TODO: Support port ranges in the form of udp:port_start-port_end
(portFile string)
| 61 | // |
| 62 | // TODO: Support port ranges in the form of udp:port_start-port_end |
| 63 | func loadPortFile(portFile string) ([]int, []int, error) { |
| 64 | portList, err := os.ReadFile(portFile) |
| 65 | if err != nil { |
| 66 | return nil, nil, err |
| 67 | } |
| 68 | |
| 69 | var portListTCP []int = []int{} |
| 70 | var portListUDP []int = []int{} |
| 71 | for _, line := range strings.Split(string(portList), "\n") { |
| 72 | if line == "" { |
| 73 | continue |
| 74 | } |
| 75 | parts := strings.Split(line, ":") |
| 76 | if len(parts) != 2 { |
| 77 | return nil, nil, fmt.Errorf("line %s in port file is invalid", line) |
| 78 | } |
| 79 | |
| 80 | port, err := strconv.Atoi(parts[1]) |
| 81 | if err != nil { |
| 82 | return nil, nil, fmt.Errorf("line %s in port file has an invalid port %s", |
| 83 | line, parts[1]) |
| 84 | } |
| 85 | if strings.Compare(parts[0], "tcp") == 0 { |
| 86 | portListTCP = append(portListTCP, port) |
| 87 | } else if strings.Compare(parts[0], "udp") == 0 { |
| 88 | portListUDP = append(portListUDP, port) |
| 89 | } else { |
| 90 | return nil, nil, fmt.Errorf("line %s in port file has an invalid network %s", |
| 91 | line, parts[0]) |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | return portListTCP, portListUDP, nil |
| 96 | } |
| 97 | |
| 98 | // Starts running the preproxy on localaddr by tunneling connections thru the given proxyaddr |
| 99 | // to the final destination targetServer for the ports configured (either by default or via the portconf file). |