Bladeren bron

Added ASN number under GeoIP information to psiphond logs.

proman 6 jaren geleden
bovenliggende
commit
f7eb9a9983
3 gewijzigde bestanden met toevoegingen van 12 en 0 verwijderingen
  1. 1 0
      psiphon/common/api.go
  2. 1 0
      psiphon/server/api.go
  3. 10 0
      psiphon/server/geoip.go

+ 1 - 0
psiphon/common/api.go

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

+ 1 - 0
psiphon/server/api.go

@@ -868,6 +868,7 @@ 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)
 
 
 	if len(authorizedAccessTypes) > 0 {
 	if len(authorizedAccessTypes) > 0 {
 		logFields["authorized_access_types"] = authorizedAccessTypes
 		logFields["authorized_access_types"] = authorizedAccessTypes

+ 10 - 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,7 @@ type GeoIPData struct {
 	Country        string
 	Country        string
 	City           string
 	City           string
 	ISP            string
 	ISP            string
+	ASN            string
 	DiscoveryValue int
 	DiscoveryValue int
 }
 }
 
 
@@ -60,6 +62,7 @@ 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,
 	}
 	}
 }
 }
 
 
@@ -195,8 +198,11 @@ 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"`
 	}
 	}
 
 
+	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 +228,10 @@ 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)
+	}
+
 	result.DiscoveryValue = calculateDiscoveryValue(
 	result.DiscoveryValue = calculateDiscoveryValue(
 		geoIP.discoveryValueHMACKey, ipAddress)
 		geoIP.discoveryValueHMACKey, ipAddress)