Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong Link-Local detection and others (getScope method) #122

Open
didix16 opened this issue Nov 2, 2020 · 3 comments
Open

Wrong Link-Local detection and others (getScope method) #122

didix16 opened this issue Nov 2, 2020 · 3 comments

Comments

@didix16
Copy link

didix16 commented Nov 2, 2020

Hi,

I'm trying to detect some scopes from IPv6 but it seems does not work, specially with link local

let ip = "2002::"
let address = new ipAddress.Addess6(ip);

// console.log(address.getScope()) -> prints 'Link local'. Should be 'Reserved'
// This is false since fe80::/10 are currently those designed for Link-Local
// 2002::/16 are reserved for 6to4

let ip = "fe80::2ff:33ff:feaa:bbcc"
let address = new ipAddress.Addess6(ip);

// console.log(address.getScope()) -> prints 'Reserved'. Should be 'Link Local'

However .isLinkLocal() seems to work fine. Maybe only getScope() method is failling.

@didix16 didix16 changed the title Wrong Link-Local detection and others Wrong Link-Local detection and others (getScope method) Nov 2, 2020
@beaugunderson
Copy link
Owner

@didix16 ah, I think you want getType(), though I do think there are some improvements that could be made, including the use of enums:

/**
 * Represents IPv6 address scopes
 * @memberof Address6
 * @static
 */
export const SCOPES: { [key: number]: string | undefined } = {
  0: 'Reserved',
  1: 'Interface local',
  2: 'Link local',
  4: 'Admin local',
  5: 'Site local',
  8: 'Organization local',
  14: 'Global',
  15: 'Reserved',
} as const;

/**
 * Represents IPv6 address types
 * @memberof Address6
 * @static
 */
export const TYPES: { [key: string]: string | undefined } = {
  'ff01::1/128': 'Multicast (All nodes on this interface)',
  'ff01::2/128': 'Multicast (All routers on this interface)',
  'ff02::1/128': 'Multicast (All nodes on this link)',
  'ff02::2/128': 'Multicast (All routers on this link)',
  'ff05::2/128': 'Multicast (All routers in this site)',
  'ff02::5/128': 'Multicast (OSPFv3 AllSPF routers)',
  'ff02::6/128': 'Multicast (OSPFv3 AllDR routers)',
  'ff02::9/128': 'Multicast (RIP routers)',
  'ff02::a/128': 'Multicast (EIGRP routers)',
  'ff02::d/128': 'Multicast (PIM routers)',
  'ff02::16/128': 'Multicast (MLDv2 reports)',
  'ff01::fb/128': 'Multicast (mDNSv6)',
  'ff02::fb/128': 'Multicast (mDNSv6)',
  'ff05::fb/128': 'Multicast (mDNSv6)',
  'ff02::1:2/128': 'Multicast (All DHCP servers and relay agents on this link)',
  'ff05::1:2/128': 'Multicast (All DHCP servers and relay agents in this site)',
  'ff02::1:3/128': 'Multicast (All DHCP servers on this link)',
  'ff05::1:3/128': 'Multicast (All DHCP servers in this site)',
  '::/128': 'Unspecified',
  '::1/128': 'Loopback',
  'ff00::/8': 'Multicast',
  'fe80::/10': 'Link-local unicast',
} as const;

re: 6to4 addresses, they don't necessarily map to a "scope" or a "type", so perhaps a new function that returns a well-known allocation would be useful?

@beaugunderson
Copy link
Owner

some more background here

@didix16
Copy link
Author

didix16 commented Nov 3, 2020

Yeah @beaugunderson. That would be nice! Also I'm missing the ULA range identification (those which starts with fd00::/8) https://en.wikipedia.org/wiki/Unique_local_address

Thanks for your effort 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants