diff --git a/config.go b/config.go index 1811f08..a28b693 100644 --- a/config.go +++ b/config.go @@ -3,7 +3,6 @@ package main import ( "bufio" "fmt" - "log" "os" "pndpd/modules" "pndpd/pndp" @@ -13,7 +12,8 @@ import ( func readConfig(dest string) { file, err := os.Open(dest) if err != nil { - log.Fatal(err) + fmt.Println("Error:", err.Error()) + os.Exit(1) } defer func(file *os.File) { _ = file.Close() diff --git a/main.go b/main.go index a28f04c..85ee735 100644 --- a/main.go +++ b/main.go @@ -16,7 +16,7 @@ import ( var Version = "Development" func main() { - fmt.Println("PNDPD Version", Version, "- Kioubit 2021") + fmt.Println("PNDPD Version", Version, "- Kioubit 2022") if len(os.Args) <= 2 { printUsage() @@ -53,7 +53,7 @@ func printUsage() { for i := range modules.ModuleList { for d := range (*modules.ModuleList[i]).Commands { if (*modules.ModuleList[i]).Commands[d].CommandLineEnabled { - fmt.Println("pndpd", (*modules.ModuleList[i]).Commands[d].Description) + fmt.Println((*modules.ModuleList[i]).Commands[d].Description) } } } diff --git a/modules/example/example.go b/modules/example/example.go index 13d9b25..a18f2b9 100644 --- a/modules/example/example.go +++ b/modules/example/example.go @@ -11,13 +11,13 @@ import ( // This is an example module func init() { commands := []modules.Command{{ - CommandText: "command1", + CommandText: "pndpd command1", Description: "This is the usage description for command1", BlockTerminate: true, CommandLineEnabled: true, ConfigEnabled: true, }, { - CommandText: "command2", + CommandText: "pndpd command2", Description: "This is the usage description for command2", BlockTerminate: false, CommandLineEnabled: false, diff --git a/modules/userInterface/userInterface.go b/modules/userInterface/userInterface.go index 86db2b8..a7533c1 100644 --- a/modules/userInterface/userInterface.go +++ b/modules/userInterface/userInterface.go @@ -5,6 +5,7 @@ package userInterface import ( "fmt" + "os" "pndpd/modules" "pndpd/pndp" "strings" @@ -13,19 +14,19 @@ import ( func init() { commands := []modules.Command{{ CommandText: "proxy", - Description: "proxy ", + Description: "pndpd proxy ", BlockTerminate: true, ConfigEnabled: true, CommandLineEnabled: true, }, { CommandText: "responder", - Description: "responder ", + Description: "pndpd responder ", BlockTerminate: true, ConfigEnabled: true, CommandLineEnabled: true, }, { CommandText: "modules", - Description: "modules available - list available modules", + Description: "pndpd modules available - list available modules", BlockTerminate: false, ConfigEnabled: false, CommandLineEnabled: true, @@ -114,14 +115,23 @@ func initCallback(callback modules.CallbackInfo) { if strings.HasPrefix(n, "filter") { filter += strings.TrimSpace(strings.TrimPrefix(n, "filter")) + ";" if strings.Contains(n, ";") { - panic("Invalid config file syntax") + showError("config: the use of semicolons is not allowed in the filter arguments") } } if strings.HasPrefix(n, "autosense") { obj.autosense = strings.TrimSpace(strings.TrimPrefix(n, "autosense")) } + if strings.Contains(n, "//") { + showError("config: comments are not allowed after arguments") + } } obj.Filter = strings.TrimSuffix(filter, ";") + if obj.autosense != "" && obj.Filter != "" { + showError("config: cannot have both a filter and autosense enabled on a proxy object") + } + if obj.Iface2 == "" || obj.Iface1 == "" { + showError("config: two interfaces need to be specified in the config file for a proxy object. (iface1 and iface2 parameters)") + } allProxies = append(allProxies, &obj) case "responder": obj := configResponder{} @@ -133,13 +143,21 @@ func initCallback(callback modules.CallbackInfo) { if strings.HasPrefix(n, "filter") { filter += strings.TrimSpace(strings.TrimPrefix(n, "filter")) + ";" if strings.Contains(n, ";") { - panic("Invalid config file syntax") + showError("config: the use of semicolons is not allowed in the filter arguments") } } if strings.HasPrefix(n, "autosense") { obj.autosense = strings.TrimSpace(strings.TrimPrefix(n, "autosense")) } - + if obj.autosense != "" && obj.Filter != "" { + showError("config: cannot have both a filter and autosense enabled on a responder object") + } + if obj.Iface == "" { + showError("config: interface not specified in the responder object. (iface parameter)") + } + if strings.Contains(n, "//") { + showError("config: comments are not allowed after arguments") + } } obj.Filter = strings.TrimSuffix(filter, ";") allResponders = append(allResponders, &obj) @@ -169,3 +187,9 @@ func shutdownCallback() { n.instance.Stop() } } + +func showError(error string) { + fmt.Println(error) + fmt.Println("Exiting due to error") + os.Exit(1) +} diff --git a/pndp/process.go b/pndp/flow.go similarity index 94% rename from pndp/process.go rename to pndp/flow.go index c6f057f..6f37cb7 100644 --- a/pndp/process.go +++ b/pndp/flow.go @@ -35,7 +35,7 @@ type ProxyObj struct { // With the optional autosenseInterface argument, the whitelist is configured based on the addresses assigned to the interface specified. This works even if the IP addresses change frequently. // Start() must be called on the object to actually start responding func NewResponder(iface string, filter []*net.IPNet, autosenseInterface string) *ResponderObj { - if filter == nil { + if filter == nil && autosenseInterface == "" { fmt.Println("WARNING: You should use a whitelist for the responder unless you really know what you are doing") } var s sync.WaitGroup @@ -59,7 +59,8 @@ func (obj *ResponderObj) start() { }() go respond(obj.iface, requests, ndp_ADV, nil, obj.filter, obj.autosense, obj.stopWG, obj.stopChan) go listen(obj.iface, requests, ndp_SOL, obj.stopWG, obj.stopChan) - fmt.Println("Started responder instance on interface", obj.iface) + fmt.Printf("Started responder instance on interface %s", obj.iface) + fmt.Println() <-obj.stopChan } @@ -130,7 +131,8 @@ func (obj *ProxyObj) start() { go listen(obj.iface2, req_iface2_adv_iface1, ndp_ADV, obj.stopWG, obj.stopChan) go respond(obj.iface1, req_iface2_adv_iface1, ndp_ADV, out_iface2_sol_questions_iface1_adv, nil, "", obj.stopWG, obj.stopChan) - fmt.Println("Started Proxy instance for interfaces:", obj.iface1, "and", obj.iface2) + fmt.Printf("Started Proxy instance on interfaces %s and %s (if enabled, the whitelist is applied on %s)", obj.iface1, obj.iface2, obj.iface2) + fmt.Println() <-obj.stopChan } diff --git a/pndp/responder.go b/pndp/responder.go index 8b63788..5e69081 100644 --- a/pndp/responder.go +++ b/pndp/responder.go @@ -73,6 +73,7 @@ func respond(iface string, requests chan *ndpRequest, respondType ndpType, ndpQu // Auto-sense if autoSense != "" { //TODO Future work: Use another sub goroutine to monitor the interface instead of checking here + filter = make([]*net.IPNet, 0) result = selectSourceIP(respondIface) autoiface, err := net.InterfaceByName(autoSense) if err != nil {