Porting multi-segment and trunk support from Havana upstream code.