Browse Source

Merge pull request #532 from gproman/asn

Added ASN number under GeoIP information to psiphond logs.
Rod Hynes 6 years ago
parent
commit
9e42e6f9b9
3 changed files with 21 additions and 0 deletions
  1. 2 0
      psiphon/common/api.go
  2. 2 0
      psiphon/server/api.go
  3. 17 0
      psiphon/server/geoip.go

+ 2 - 0
psiphon/common/api.go

@@ -33,6 +33,8 @@ type GeoIPData struct {
 	Country        string
 	Country        string
 	City           string
 	City           string
 	ISP            string
 	ISP            string
+	ASN            string
+	ASO            string
 	DiscoveryValue int
 	DiscoveryValue int
 }
 }
 
 

+ 2 - 0
psiphon/server/api.go

@@ -868,6 +868,8 @@ func getRequestLogFields(
 	logFields["client_region"] = strings.Replace(geoIPData.Country, " ", "_", -1)
 	logFields["client_region"] = strings.Replace(geoIPData.Country, " ", "_", -1)
 	logFields["client_city"] = strings.Replace(geoIPData.City, " ", "_", -1)
 	logFields["client_city"] = strings.Replace(geoIPData.City, " ", "_", -1)
 	logFields["client_isp"] = strings.Replace(geoIPData.ISP, " ", "_", -1)
 	logFields["client_isp"] = strings.Replace(geoIPData.ISP, " ", "_", -1)
+	logFields["client_asn"] = strings.Replace(geoIPData.ASN, " ", "_", -1)
+	logFields["client_aso"] = strings.Replace(geoIPData.ASO, " ", "_", -1)
 
 
 	if len(authorizedAccessTypes) > 0 {
 	if len(authorizedAccessTypes) > 0 {
 		logFields["authorized_access_types"] = authorizedAccessTypes
 		logFields["authorized_access_types"] = authorizedAccessTypes

+ 17 - 0
psiphon/server/geoip.go

@@ -27,6 +27,7 @@ import (
 	"net"
 	"net"
 	"os"
 	"os"
 	"path/filepath"
 	"path/filepath"
+	"strconv"
 	"time"
 	"time"
 
 
 	"github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon/common"
 	"github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon/common"
@@ -50,6 +51,8 @@ type GeoIPData struct {
 	Country        string
 	Country        string
 	City           string
 	City           string
 	ISP            string
 	ISP            string
+	ASN            string
+	ASO            string
 	DiscoveryValue int
 	DiscoveryValue int
 }
 }
 
 
@@ -60,6 +63,8 @@ func NewGeoIPData() GeoIPData {
 		Country: GEOIP_UNKNOWN_VALUE,
 		Country: GEOIP_UNKNOWN_VALUE,
 		City:    GEOIP_UNKNOWN_VALUE,
 		City:    GEOIP_UNKNOWN_VALUE,
 		ISP:     GEOIP_UNKNOWN_VALUE,
 		ISP:     GEOIP_UNKNOWN_VALUE,
+		ASN:     GEOIP_UNKNOWN_VALUE,
+		ASO:     GEOIP_UNKNOWN_VALUE,
 	}
 	}
 }
 }
 
 
@@ -195,8 +200,12 @@ func (geoIP *GeoIPService) Lookup(ipAddress string) GeoIPData {
 			Names map[string]string `maxminddb:"names"`
 			Names map[string]string `maxminddb:"names"`
 		} `maxminddb:"city"`
 		} `maxminddb:"city"`
 		ISP string `maxminddb:"isp"`
 		ISP string `maxminddb:"isp"`
+		ASN int    `maxminddb:"autonomous_system_number"`
+		ASO string `maxminddb:"autonomous_system_organization"`
 	}
 	}
 
 
+	geoIPFields.ASN = -1
+
 	// Each database will populate geoIPFields with the values it contains. In the
 	// Each database will populate geoIPFields with the values it contains. In the
 	// current MaxMind deployment, the City database populates Country and City and
 	// current MaxMind deployment, the City database populates Country and City and
 	// the separate ISP database populates ISP.
 	// the separate ISP database populates ISP.
@@ -222,6 +231,14 @@ func (geoIP *GeoIPService) Lookup(ipAddress string) GeoIPData {
 		result.ISP = geoIPFields.ISP
 		result.ISP = geoIPFields.ISP
 	}
 	}
 
 
+	if geoIPFields.ASN != -1 {
+		result.ASN = strconv.Itoa(geoIPFields.ASN)
+	}
+
+	if geoIPFields.ASO != "" {
+		result.ASO = geoIPFields.ASO
+	}
+
 	result.DiscoveryValue = calculateDiscoveryValue(
 	result.DiscoveryValue = calculateDiscoveryValue(
 		geoIP.discoveryValueHMACKey, ipAddress)
 		geoIP.discoveryValueHMACKey, ipAddress)