6 Commits

Author SHA1 Message Date
Yoshiyuki Mineo
8d195df6f7 Fix a missing link (#65) 2025-05-01 19:25:49 +09:00
Yoshiyuki Mineo
410eb250e3 Update Go versions (#64) 2025-05-01 19:15:37 +09:00
Yoshiyuki Mineo
94f43cfd99 Update Go versions (#60) 2024-10-13 22:30:52 +09:00
Yoshiyuki Mineo
b9b40b47a5 Update go versions (#54) 2024-04-30 15:50:36 +09:00
Yoshiyuki Mineo
a0558cef64 Link local (#53)
* Allow IPv4 Link Local addresses (#50)

* Allow IPv4 Link Local addresses

Allow the use of link local addresses

* Update sonyflake.go

* Update sonyflake.go

* Update a comment

---------

Co-authored-by: Flavio Crisciani <f.crisciani@gmail.com>
2024-04-30 15:06:58 +09:00
David E. Wheeler
fc2f84a086 Use net.IP.Equal instead of bytes.Equal (#49)
As suggested by go-staticcheck.
2023-11-06 14:32:46 +09:00
4 changed files with 6 additions and 6 deletions

View File

@@ -4,7 +4,7 @@ jobs:
test:
strategy:
matrix:
go-version: [1.20.x, 1.21.x]
go-version: [1.23.x, 1.24.x]
os: [ubuntu-latest]
runs-on: ${{matrix.os}}
steps:

View File

@@ -83,8 +83,8 @@ the function AmazonEC2MachineID that returns the lower 16-bit private IP address
It also works correctly on Docker
by retrieving [instance metadata](http://docs.aws.amazon.com/en_us/AWSEC2/latest/UserGuide/ec2-instance-metadata.html).
[AWS VPC](http://docs.aws.amazon.com/en_us/AmazonVPC/latest/UserGuide/VPC_Subnets.html)
is assigned a single CIDR with a netmask between /28 and /16.
[AWS IPv4 VPC](https://docs.aws.amazon.com/vpc/latest/userguide/vpc-cidr-blocks.html)
is usually assigned a single CIDR with a netmask between /28 and /16.
So if each EC2 instance has a unique private IP address in AWS VPC,
the lower 16 bits of the address is also unique.
In this common case, you can use AmazonEC2MachineID as Settings.MachineID.

View File

@@ -178,8 +178,9 @@ func privateIPv4(interfaceAddrs types.InterfaceAddrs) (net.IP, error) {
}
func isPrivateIPv4(ip net.IP) bool {
// Allow private IP addresses (RFC1918) and link-local addresses (RFC3927)
return ip != nil &&
(ip[0] == 10 || ip[0] == 172 && (ip[1] >= 16 && ip[1] < 32) || ip[0] == 192 && ip[1] == 168)
(ip[0] == 10 || ip[0] == 172 && (ip[1] >= 16 && ip[1] < 32) || ip[0] == 192 && ip[1] == 168 || ip[0] == 169 && ip[1] == 254)
}
func lower16BitPrivateIP(interfaceAddrs types.InterfaceAddrs) (uint16, error) {

View File

@@ -1,7 +1,6 @@
package sonyflake
import (
"bytes"
"errors"
"fmt"
"net"
@@ -259,7 +258,7 @@ func TestPrivateIPv4(t *testing.T) {
return
}
if bytes.Equal(actual, tc.expected) {
if net.IP.Equal(actual, tc.expected) {
return
} else {
t.Errorf("error: expected: %s, but got: %s", tc.expected, actual)