Sample Netgraph code that unhooks and rehooks without losing connection

Julian Elischer julian at elischer.org
Tue Jul 3 00:42:29 UTC 2007


Alexander Motin wrote:
> Martha Pasikatan wrote:
>> I would like to be able to unhook a pppoe node hooked to link0 and 
>> rehook it to a tee node.  Can anyone give me a sample on how to do this?  
> 
> That's impossible. As soon as pppoe node hook is disconnected all 
> related info will be destroyed and session will be terminated. You 
> should put there some other node like ng_tee to prevent session 
> termination.
> 


when you say link0, do you mean an ethernet side connection or a 
session-side connection?

either way you can't do that because the act of removing the hook will
remove all the information for the session..
And the action of removing the ethernet hook will I think remove 
the whole node. This is however only an implementation detail.
Given a good enough reason I could  make a workaround..

Internally it would be in the form of either a new command 
similar to mkpeer like:

ngctl insert {node_type} 
             {target_node:}
             {target_hook}
             {insert_type_hook_a}
             {insert_type_hook_b}

or maybe a more specific version for tee-only.

ngctl 
mkpeer . tee any left2right
msg tee "insert" {target=some_node, hook=some_hook, side=left}

the hard part is that the locking gets really tricky..
you need to gain the locks on both sides of the  connection 
at the same time without having some sort of LOR style problems.

if we KNOW that the node being inserted is TEE and has no 
other users, then maybe we could take some shortcuts,
connecting the links up in an asymmetrical manner so that links being followed are 
always safe.







More information about the freebsd-net mailing list