Skip to content

Commit

Permalink
Fork IPv6 to separate vNIC (#33) untested
Browse files Browse the repository at this point in the history
  • Loading branch information
lsthompson authored May 19, 2024
1 parent 02c2bb7 commit 0ab97dc
Showing 1 changed file with 33 additions and 7 deletions.
40 changes: 33 additions & 7 deletions modules/servers/pvewhmcs/pvewhmcs.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,22 +182,26 @@ function pvewhmcs_CreateAccount($params) {
} else {
$vm_settings['vmid'] = $params["serviceid"];
if ($plan->vmtype == 'lxc') {
// Process LXC preparation
/////////////////////////////
// Process LXC preparation //
/////////////////////////////
$vm_settings['ostemplate'] = $plan->storage . ':vztmpl/' . $params['customfields']['Template'];
$vm_settings['swap'] = $plan->swap;
$vm_settings['rootfs'] = $plan->storage . ':' . $plan->disk;
$vm_settings['bwlimit'] = $plan->diskio;
$vm_settings['net0'] = 'name=eth0,bridge=' . $plan->bridge . $plan->vmbr . ',ip=' . $ip->ipaddress . '/' . mask2cidr($ip->mask) . ',gw=' . $ip->gateway;
if (!empty($plan->ipv6) && $plan->ipv6 != '0') {
// Standard prep for the 2nd int.
$vm_settings['net1'] = 'name=eth1,bridge=' . $plan->bridge . $plan->vmbr;
// Handling different IPv6 configs
switch ($plan->ipv6) {
case 'auto':
// Passes 'auto' directly, triggering SLAAC
$vm_settings['net0'] .= ',ip6=auto';
$vm_settings['net1'] .= ',ip6=auto';
break;
case 'dhcp':
// Passes 'dhcp' directly
$vm_settings['net0'] .= ',ip6=dhcp';
$vm_settings['net1'] .= ',ip6=dhcp';
break;
case 'prefix':
// Placeholder for future development - currently does nothing
Expand All @@ -207,15 +211,22 @@ function pvewhmcs_CreateAccount($params) {
// Handle any unexpected IPv6 settings - logging, etc
break;
}
// VLAN tag, only for v6
if(!empty($plan->vlanid)){
$vm_settings['net1'] .= ',trunk=' . $plan->vlanid;
}
}
// VLAN tag, only for v4
if(!empty($plan->vlanid)){
$vm_settings['net0'] .= ',trunk=' . $plan->vlanid;
}
$vm_settings['nameserver'] = '76.76.2.0 76.76.10.0';
$vm_settings['onboot'] = $plan->onboot;
$vm_settings['password'] = $params['customfields']['Password'];
} else {
// Process QEMU preparation
//////////////////////////////
// Process QEMU preparation //
//////////////////////////////
$vm_settings['ostype'] = $plan->ostype;
$vm_settings['sockets'] = $plan->cpus;
$vm_settings['cores'] = $plan->cores;
Expand All @@ -226,18 +237,18 @@ function pvewhmcs_CreateAccount($params) {
switch ($plan->ipv6) {
case 'auto':
// Passes 'auto' directly, triggering SLAAC
$vm_settings['net0'] .= ',ip6=auto';
$vm_settings['ipconfig1'] = 'ip6=auto';
break;
case 'dhcp':
// Passes 'dhcp' directly
$vm_settings['net0'] .= ',ip6=dhcp';
$vm_settings['ipconfig1'] = 'ip6=dhcp';
break;
case 'prefix':
// Placeholder for future development - currently does nothing
// TODO: Handle 'prefix' case once prefix allocation logic is developed
break;
default:
// Handle any unexpected ipv6 settings, possibly log this case
// Handle any unexpected IPv6 settings - logging, etc
break;
}
}
Expand All @@ -257,6 +268,7 @@ function pvewhmcs_CreateAccount($params) {

/* Network Specifics - Bridge, Rate & Trunk/VLAN */
if ($plan->netmode != 'none') {
// Perform the additions for IPv4 (net0/ipconfig0)
$vm_settings['net0'] = $plan->netmodel;
if ($plan->netmode == 'bridge') {
$vm_settings['net0'] .= ',bridge=' . $plan->bridge . $plan->vmbr;
Expand All @@ -268,6 +280,20 @@ function pvewhmcs_CreateAccount($params) {
if (!empty($plan->vlanid)) {
$vm_settings['net0'] .= ',trunk=' . $plan->vlanid;
}
// Check if ipconfig1 exists, and then do the same for net1 if so
if (isset($vm_settings['ipconfig1'])) {
$vm_settings['net1'] = $plan->netmodel;
if ($plan->netmode == 'bridge') {
$vm_settings['net1'] .= ',bridge=' . $plan->bridge . $plan->vmbr;
}
$vm_settings['net1'] .= ',firewall=' . $plan->firewall;
if (!empty($plan->netrate)) {
$vm_settings['net1'] .= ',rate=' . $plan->netrate;
}
if (!empty($plan->vlanid)) {
$vm_settings['net1'] .= ',trunk=' . $plan->vlanid;
}
}
}
/* end of network settings */
}
Expand Down

0 comments on commit 0ab97dc

Please sign in to comment.