Where is $device['context_name'] set? IPv6 problem

well, i maybe solved the issue

but on hacky way
i know what is the problem

the whole IPv6 stack is affected !!!

but need help
where is $device[‘context_name’] set first time ?

after few day of debugging i lost my eyes :frowning:

yes
definitive

problem is that recent LNMS

  1. does not show ipv6 addresses (overview → ipv6 address)
  2. cross connect interfaces from different network

the root of problem is in database
table “ipv6_addresses” have incorect value in “context_name” cell

and
/includes/discovery/functions.php
function discover_process_ipv6(&$valid, $ifIndex, $ipv6_address, $ipv6_prefixlen, $ipv6_origin, $context_name = ‘’)

update table with $device[‘context_name’] which is not NULL , it is “”
but function try after that to match NULL from DB

so, if anyone could help, where is $device[‘context_name’] set first ?

found it
includes/discovery/ipv6-addresses.inc.php

@murrant @Jellyfrog
is this is acceptable as FIX/PR ??

foreach (DeviceCache::getPrimary()->getVrfContexts() as $context_name) {
+    //empty string instead of NULL
+    $context_name = ($context_name == NULL) ? '' : $context_name;
    $device['context_name'] = $context_name;

tested on updated LNMS ubuntu 20.04 / mysql 8.0.27 in ← production

tested on virgin LNMS ubuntu 20.04 / mariadb Ver 15.1 ← test lab

problem was that ipv6_addresses table was not populated with proper ipv6_network_id because of NULL/empty string mismatch
that caused whole trouble with ipv6 address missing / cross connecting because every ipv6_address was in same (empty) ipv6_network_id

now it is OK

I’m confused. Do you want null or not?

$context_name = $context_name ?? ""

old fashioned :slight_smile:

if ($device_context == NULL) {
    $device_context = ''
}

no, i don’t want null
empty string is needed

We should use null were possible tho.

@Jellyfrog

this is the root of problems

            // Update IPv6 network ID if not set
            if ($context_name == null) {
                $ipv6_network_id = dbFetchCell('SELECT `ipv6_network_id` FROM `ipv6_networks` WHERE `ipv6_network` = ? AND `context_name` IS NULL', [$ipv6_network]);
            } else {

IS NULL

it is never be NULL because

        } else {
            //Update Context
            dbUpdate(['context_name' => $device['context_name']], 'ipv6_networks', '`ipv6_network` = ?', [$ipv6_network]);
            echo 'n';

is constantly updated with not null value (empty string)

two $context_name does not match
one from $device, other on function input

that is why i propose

foreach (DeviceCache::getPrimary()->getVrfContexts() as $context_name) {
    //empty string intead of NULL
    $context_name = ($context_name == NULL) ? '' : $context_name;
    $device['context_name'] = $context_name;

and we never hit NULL condition
it could be removed completly from functions.inc.php

I suggest fixing the source instead of patching the symptom then :slight_smile:

well …
i think i done my job here

opened issue 24 days ago
nobody reacted

proved that this error does not exists in older LNMS
tracked down where is error
reversing from “why WEB does not show IPv6” and going backward
find the root cause

if i need to make my tip,

PR Common contexts for polling (#13158)

there was introduced
public function getVrfContexts(): array
{
return $this->vrfLites->isEmpty() ? [’’] : $this->vrfLites->pluck(‘context_name’)->all();
}

so, from my point of view, i done my job

maybe you or other skilled PHP programmer could solve this

after all, it is huge drawback that IPv6 stack is not functioning in LNMS

1 Like

FYI in PHP null == '' is true.

Also, if you were to update the SQL queries to use Laravel Fluent/Eloquent, it would fix the issue automatically because it builds the queries to correctly handle null or ‘’.

so, from my point of view, i done my job Who is going to finish the “job” then?

yes @murrant , wrong copy/paste
space is left out

whatever
ok, will see,
is App\Models\Ipv6xxxx already in function ?
like Vlans ?

ok
made it with Laravel syntax
looks like it is working
few day test, will send PR

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.