Pages

Tuesday, 27 October 2009

How to disable CDP-4-NATIVE_VLAN_MISMATCH (native vlan mismatch)

Cisco switches support CDP and use it to help us in a number of ways. One of them is to detect native VLAN mismatch between two connected ports. For 99% of the time this is a "good thing to do" (tm) but there are some corner cases where this is not what you want.

For example, if you have a switch that is connected with another switch and their connected ports are configured as access ports (and not trunk ports) then this message doesn't make much sense.

Well... it does...

Cisco switches also support VTP which eases the VLAN management task. For VTP to work, switches that are under the same "local network" are also under the same "VTP domain". A VTP domain logically groups switches.

Now, here is the problem: Two switches connected using access mode that are in the same VTP domain should share the same VLAN configuration, even if they are configured as transparent.

What to do: To bypass this problem you have to change the vtp domain on those switches so that it doesn't match. If you haven't changed that already, they most probably are not in any VTP domain at all or they are in the same VTP domain.

The solution:

  1. Configure at least one of the two switches to be in transparent mode. You may not want that, but if you don't know what this means then just do it:

    Switch(config)# vtp mode transparent

  2. Change the VTP domain of that switch:

    Switch(config)# vtp domain a_unique_name


    (you may want to use the hostname)



... and this annoying message:


Oct 27 12:16:29.352 EET: %CDP-4-NATIVE_VLAN_MISMATCH: Native VLAN mismatch discovered on GigabitEthernet2/6 (2), with sw-el0 GigabitEthernet0/8 (1).


will be gone

Thursday, 17 September 2009

Tuesday, 25 August 2009

hal-acl-tool, pam and high cpu usage

For a long time now i see my CPU usage rising and falling back every some seconds. This is very annoying and it really slows things down. Finally, I found (to some extend) what causes this problem. Using "udevadm monitor" I show that the CPU was rising whenever a uid-add event was created by the kernel:
$ udevadm monitor
KERNEL[1250930556.085871] add /kernel/uids/111 (uids)
UDEV [1250930556.087481] add /kernel/uids/111 (uids)
KERNEL[1250930556.099782] remove /kernel/uids/111 (uids)
UDEV [1250930556.099818] remove /kernel/uids/111 (uids)


I also found that the program that causes the CPU load is "hal-acl-tool" but not directly. In fact, hal-acl-tool wasn't consuming a lot of CPU and top wasn't showing anything. With process accounting I found that there are 1000s of invocations of /usr/lib/policykit/polkit-read-auth-helper:
$ lastcomm |grep polkit-read-aut | wc -l
61161

in a couple of minutes (!). This seems to be a bug that troubles other people too.

Finaly, I concluded that the problem is not related to uid-add events but to session creation. The problem is caused by console kit and its pam hook: pam_ck_connector.so. For newer debian versions (read: testing) you can disable this by running (as root) pam-auth-update and deselecting the "ConsoleKit Session Management".

WARNING: I'm not aware of the drawbacks of disabling "ConsoleKit Session Management", so do this at your own risk.

Saturday, 13 June 2009

php foreach by reference

Here's an interesting "feature" (bug?) for php. Recent PHP versions support this syntax for foreach:

foreach ($myarray as &$v)
$v['koko']='lala';

This allows easy changes to the actual table by using references and not acting on a copy.

- but -

If you do this:

$myarray=array(array('a'=>1), array('a'=>2), array('a'=>3));

foreach ($myarray as &$v)
$v['b']=1;

foreach ($myarray as $v);

print_r($myarray);

You manage to remove the last element of $myarray (!!!). This is the output:

Array
(
[0] => Array
(
[a] => 1
[b] => 1
)

[1] => Array
(
[a] => 2
[b] => 1
)

[2] => Array
(
[a] => 2
[b] => 1
)

)


Now, if you change the code to:

$myarray=array(array('a'=>1), array('a'=>2), array('a'=>3));

foreach ($myarray as &$v)
$v['b']=1;

foreach ($myarray as $v2);

print_r($myarray);

The bug is gone. The output is correct:

Array
(
[0] => Array
(
[a] => 1
[b] => 1
)

[1] => Array
(
[a] => 2
[b] => 1
)

[2] => Array
(
[a] => 3
[b] => 1
)
)


To my knowledge, this happens because $v is kept as a reference to the last element when the first foreach is finished. Then, when the second foreach is ran, some assignments are performed to $v, destroying its last element.

Saturday, 7 March 2009

KAutostart and python

This one took me many hours to debug:

For KDE 4 and python there can be a hard to debug problem with KAutostart usage.

Suppose you have a window class

class MyWindow(KDialig, Ui_Dialog):
def __init__(self):
self.kas = KAutostart('myapp')
self.kas.setAutostarts(True)


You may find that the setAutostarts() doesn't actually work. This is because MyWindow references kas and kas references MyWindow (as the parent object) (or the application - I'm not sure). The problem is that KAutostart() stores the information when it is deleted (in it's destructor) and since it is never deleted it won't store anything.

You need to understand that the destructors won't be called even when the program exits, because of the circular reference.

To solve the problem call:

self.kas=None

at some point.

Have a look here for more on python and its destructors.

Saturday, 17 January 2009

Loans

Here's an example about how loans seem to currently work and what they mean to the society:

Suppose we have two persons (Ann and Bob) and a Bank. The Bank has no money at all, Ann has 10.000 euros (or dollars or whatever) and Bob has two cars which is willing to sell for 8.000 euros each.

Ann gives Bob 8.000 euros and she buys the first car. Now Ann has 2.000 euros and Bob has 8.000 euros. Bob goes to the bank and deposits the money, so the Bank now has 8.000 euros.

Ann goes to the bank and gets a 6.000 euros loan which she will repay as 7.000 euros in two years. Now Ann has 8.000 euros (6.000 from the loan and 2.000 pre-existing cash) which she uses to buy the second car. Bob gets the 8.000 euros and deposits them to the bank too.

At this point:

  • Ann has two cars and a dept of 6.000 euros to the bank that she may not repay

  • Bob has 16.000 euros in deposits

  • The bank has 10.000 euros and a loan for 6.000 euros (that will become 7.000 after two years)



The 1.000.000 dollars question is: Does bob have 16.000 euros ?

The fact is that Bob actually thinks that he has 16.000 euros which he can use but in fact he only has 10.000.

What's going on?

This is a clever way to rename future money (the 6.000 euros) to current money. You can see this problem as an issue of tagging where money should be tagged either as "existing" or "loaned/future/not-yet-available" money. Currently this isn't possible since loans are given in cash and not in another kind of debt bills and the fact is that we (the sum of all humans) currently have much less money than we actually think we have.