IPv6 changes

This commit is contained in:
Peter Hormanns 2019-03-07 19:37:57 +01:00
parent c09e9bba2e
commit 35727b04e3
15 changed files with 110 additions and 44 deletions

View File

@ -0,0 +1,60 @@
package de.hsadmin.core.util;
import java.net.InetAddress;
import java.net.UnknownHostException;
import de.hsadmin.core.qserv.ProcessorException;
public class IPv6Trick {
private static final String IPv4_83_223_79 = "83.223.79"; // Alboin-Kontor Berlin
private static final String IPv4_83_223_91 = "83.223.91"; // Alboin-Kontor Berlin
private static final String IPv4_83_223_95 = "83.223.95"; // Alboin-Kontor Berlin
private static final String IPv6_PREFIX_AK = "2a01:37:1000::1";
private static final String IPv4_83_223_78 = "83.223.78"; // e-Shelter Berlin
private static final String IPv4_83_223_94 = "83.223.94"; // e-Shelter Berlin
private static final String IPv6_PREFIX_ES = "2a01:37:2000::1";
public static String convertIPv4ToIPv6(final String ipv4address) throws ProcessorException {
if (ipv4address == null || ipv4address.length() == 0) {
throw new ProcessorException("no IPv4 address given");
}
try {
final InetAddress inetV4Address = InetAddress.getByName(ipv4address);
if (ipv4address.startsWith(IPv4_83_223_79) // Alboin-Kontor Berlin
|| ipv4address.startsWith(IPv4_83_223_91)
|| ipv4address.startsWith(IPv4_83_223_95) ) {
return embedIPv4Address(inetV4Address, InetAddress.getByName(IPv6_PREFIX_AK));
}
if (ipv4address.startsWith(IPv4_83_223_78) // e-Shelter Berlin
|| ipv4address.startsWith(IPv4_83_223_94) ) {
return embedIPv4Address(inetV4Address, InetAddress.getByName(IPv6_PREFIX_ES));
}
} catch (UnknownHostException e) {
throw new ProcessorException(e);
}
throw new ProcessorException("unknown IPv4 address given");
}
private static String embedIPv4Address(final InetAddress ipv4address, final InetAddress ipv6Mask) throws UnknownHostException {
final byte[] ipv4Bytes = ipv4address.getAddress();
final byte[] ipv6Bytes = ipv6Mask.getAddress();
ipv6Bytes[10] = ipv4Bytes[0];
ipv6Bytes[11] = ipv4Bytes[1];
ipv6Bytes[12] = ipv4Bytes[2];
ipv6Bytes[13] = ipv4Bytes[3];
ipv6Bytes[14] = 0;
ipv6Bytes[15] = 0;
final InetAddress ipv6Address = InetAddress.getByAddress(ipv6Bytes);
final String ipv6String = ipv6Address.getHostAddress();
if (ipv6String.startsWith("/")) {
return ipv6String.substring(1);
} else {
return ipv6String;
}
}
}

View File

@ -129,7 +129,7 @@ public class DomainProcessorFactory implements EntityProcessorFactory {
}
private Processor createMailinSetupProcessor(EntityManager em, Domain dom, Pac pac) throws ProcessorException {
final String inetAddr = pac.getCurINetAddr().getInetAddr();
final String inet4Addr = pac.getCurINetAddr().getInet4Addr();
final CompoundProcessor cp = new CompoundProcessor(
createPostgreyConfiguration(em),
new ShellProcessor("postmap -r -i /etc/postfix-mailin/relaydomains || true",
@ -150,8 +150,8 @@ public class DomainProcessorFactory implements EntityProcessorFactory {
}
cp.appendProcessor(
new ShellProcessor("postmap -r -i /etc/postfix-mailin/transport || true",
dom.getName() + " smtp:" + inetAddr + ":225\n" +
"." + dom.getName() + " smtp:" + inetAddr + ":225\n")
dom.getName() + " smtp:" + inet4Addr + ":225\n" +
"." + dom.getName() + " smtp:" + inet4Addr + ":225\n")
);
} else {
cp.appendProcessor(

View File

@ -3,7 +3,7 @@
# Do not edit manually. Changes will be overwritten.
#
<VirtualHost ${pac.curINetAddr.inetAddr}:80 ${pac.oldINetAddr.inetAddr}:80 ${pac.curINet6Addr.inetAddr}:80 ${pac.oldINet6Addr.inetAddr}:80>
<VirtualHost ${pac.curINetAddr.inet4Addr}:80 ${pac.oldINetAddr.inet4Addr}:80 ${pac.curINetAddr.inet6Addr}:80 ${pac.oldINetAddr.inet6Addr}:80>
ServerName ${dom.name}
ServerAlias ${dom.serveraliases}
ServerAdmin webmaster@${dom.name}
@ -76,7 +76,7 @@
Action application/x-httpd-php /fastcgi-bin/phpstub
</VirtualHost>
<VirtualHost ${pac.curINetAddr.inetAddr}:443 ${pac.oldINetAddr.inetAddr}:443 ${pac.curINet6Addr.inetAddr}:443 ${pac.oldINet6Addr.inetAddr}:443>
<VirtualHost ${pac.curINetAddr.inet4Addr}:443 ${pac.oldINetAddr.inet4Addr}:443 ${pac.curINetAddr.inet6Addr}:443 ${pac.oldINetAddr.inet6Addr}:443>
ServerName ${dom.name}
ServerAlias ${dom.serveraliases}
ServerAdmin webmaster@${dom.name}

View File

@ -4,5 +4,5 @@
//
#foreach( $domain in ${domains} )
zone "${domain.name}" { type slave; file "sec.${domain.name}"; masters { ${domain.user.pac.hive.inetAddr.inetAddr}; }; };
zone "${domain.name}" { type slave; file "sec.${domain.name}"; masters { ${domain.user.pac.hive.inetAddr.inet4Addr}; }; };
#end

View File

@ -15,12 +15,12 @@ ${dom.name}. IN MX 30 mailin1.hostsharing.net.
${dom.name}. IN MX 30 mailin2.hostsharing.net.
${dom.name}. IN MX 30 mailin3.hostsharing.net.
${dom.name}. IN A ${pac.curINetAddr.inetAddr}
;${dom.name}. IN AAAA ${pac.curINet6Addr.inetAddr}
${dom.name}. IN A ${pac.curINetAddr.inet4Addr}
;${dom.name}. IN AAAA ${pac.curINetAddr.inet6Addr}
*.${dom.name}. IN MX 30 mailin1.hostsharing.net.
*.${dom.name}. IN MX 30 mailin2.hostsharing.net.
*.${dom.name}. IN MX 30 mailin3.hostsharing.net.
*.${dom.name}. IN A ${pac.curINetAddr.inetAddr}
;*.${dom.name}. IN AAAA ${pac.curINet6Addr.inetAddr}
*.${dom.name}. IN A ${pac.curINetAddr.inet4Addr}
;*.${dom.name}. IN AAAA ${pac.curINetAddr.inet6Addr}

View File

@ -145,7 +145,7 @@ public class Hive extends AbstractEntity implements Serializable {
}
public String getDefaultGateway() {
String hiveIP = getInetAddr().getInetAddr();
String hiveIP = getInetAddr().getInet4Addr();
return Config.getInstance().getProperty("hsadmin.default_gateway", hiveIP.substring(0, hiveIP.lastIndexOf('.')) + ".1");
}
}

View File

@ -13,6 +13,8 @@ import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import de.hsadmin.core.model.AbstractEntity;
import de.hsadmin.core.qserv.ProcessorException;
import de.hsadmin.core.util.IPv6Trick;
import de.hsadmin.mods.user.UnixUser;
@Entity(name = "INetAddresses")
@ -51,7 +53,7 @@ public class INetAddress extends AbstractEntity implements Serializable {
@Override
public String createStringKey() {
return getInetAddr();
return getInet4Addr();
}
@Override
@ -67,10 +69,14 @@ public class INetAddress extends AbstractEntity implements Serializable {
this.id = id;
}
public String getInetAddr() {
public String getInet4Addr() {
return name;
}
public String getInet6Addr() throws ProcessorException {
return IPv6Trick.convertIPv4ToIPv6(name);
}
public void setInetAddr(String inetAddr) {
this.name = inetAddr;
}

View File

@ -49,10 +49,10 @@ public class PacModuleImpl extends AbstractModuleImpl {
basepac = (BasePac) qBasepac.getSingleResult();
pac.setBasepac(basepac);
INetAddress curINetAddr = pac.getCurINetAddr();
if (curINetAddr == null || curINetAddr.getInetAddr() == null || curINetAddr.getInetAddr().length() == 0) {
if (curINetAddr == null || curINetAddr.getInet4Addr() == null || curINetAddr.getInet4Addr().length() == 0) {
throw new HSAdminException("curinetaddr required");
}
Query qINetAddr = em.createNativeQuery("SELECT * FROM inet_addr WHERE inet_addr = inet '" + curINetAddr.getInetAddr() + "'", INetAddress.class);
Query qINetAddr = em.createNativeQuery("SELECT * FROM inet_addr WHERE inet_addr = inet '" + curINetAddr.getInet4Addr() + "'", INetAddress.class);
curINetAddr = (INetAddress) qINetAddr.getSingleResult();
pac.setCurINetAddr(curINetAddr);
Customer customer = pac.getCustomer();

View File

@ -175,30 +175,30 @@ public class PacProcessorFactory implements EntityProcessorFactory {
);
}
private Processor createIfUp(final Pac pac) {
return new CompoundProcessor(new ShellProcessor("ip addr add "
+ pac.getCurINetAddr().getInetAddr()
private Processor createIfUp(final Pac pac) throws ProcessorException {
return new CompoundProcessor(
new ShellProcessor("ip addr add "
+ pac.getCurINetAddr().getInet4Addr()
+ "/32 dev eth0"
+ pac.getName()
),
new ShellProcessor("ip addr add "
+ pac.getCurINet6Addr().getInetAddr()
+ "/128 dev eth0 noprefixroute preferred_lft 0"
+ pac.getName()
));
new ShellProcessor("ip addr add "
+ pac.getCurINetAddr().getInet6Addr()
+ "/128 dev eth0 noprefixroute preferred_lft 0"
)
);
}
private Processor createIfDown(final Pac pac) {
return new CompoundProcessor(new ShellProcessor("ip addr del "
+ pac.getCurINetAddr().getInetAddr()
private Processor createIfDown(final Pac pac) throws ProcessorException {
return new CompoundProcessor(
new ShellProcessor("ip addr del "
+ pac.getCurINetAddr().getInet4Addr()
+ "/32 dev eth0"
+ pac.getName()
),
new ShellProcessor("ip addr add "
+ pac.getCurINet6Addr().getInetAddr()
+ "/128 dev eth0 noprefixroute preferred_lft 0"
+ pac.getName()
));
new ShellProcessor("ip addr del "
+ pac.getCurINetAddr().getInet6Addr()
+ "/128 dev eth0 noprefixroute preferred_lft 0"
)
);
}
private UnixUser getPacAdminUser(Pac pac) throws ProcessorException {

View File

@ -11,10 +11,10 @@ ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts
${hive.inetAddr.inetAddr} ${hive.name}.hostsharing.net ${hive.name} localhive
${hive.inet6Addr.inetAddr} ${hive.name}.hostsharing.net ${hive.name} localhive
${hive.inetAddr.inet4Addr} ${hive.name}.hostsharing.net ${hive.name} localhive
${hive.inetAddr.inet6Addr} ${hive.name}.hostsharing.net ${hive.name} localhive
#foreach( $pac in ${hive.webpacs} )
${pac.curINetAddr.inetAddr} ${pac.name}.hostsharing.net ${pac.name}
${pac.curINet6Addr.inetAddr} ${pac.name}.hostsharing.net ${pac.name}
${pac.curINetAddr.inet4Addr} ${pac.name}.hostsharing.net ${pac.name}
${pac.curINetAddr.inet6Addr} ${pac.name}.hostsharing.net ${pac.name}
#end

View File

@ -4,7 +4,7 @@
#
#foreach( $pac in ${hive.webpacs} )
<VirtualHost ${pac.curINetAddr.inetAddr}:80 ${pac.curINet6Addr.inetAddr}:80>
<VirtualHost ${pac.curINetAddr.inet4Addr}:80 ${pac.curINetAddr.inet6Addr}:80>
ServerName _
ServerAdmin webmaster@${pac.name}.hostsharing.net
@ -15,7 +15,7 @@
</VirtualHost>
<VirtualHost ${pac.curINetAddr.inetAddr}:443 ${pac.curINet6Addr.inetAddr}:443>
<VirtualHost ${pac.curINetAddr.inet4Addr}:443 ${pac.curINetAddr.inet6Addr}:443>
ServerName _
ServerAdmin webmaster@${pac.name}.hostsharing.net

View File

@ -4,5 +4,5 @@
#
#
#foreach( $pac in ${hive.webpacs} )
eth0:${pac.name}:${pac.curINetAddr.inetAddr}/32
eth0:${pac.name}:${pac.curINetAddr.inet4Addr}/32
#end

View File

@ -4,5 +4,5 @@
#
#
#foreach( $pac in ${hive.webpacs} )
eth0:${pac.name}:${pac.curINet6Addr.inetAddr}/128
eth0:${pac.name}:${pac.curINetAddr.inet6Addr}/128
#end

View File

@ -4,7 +4,7 @@
#
#foreach( $pac in ${hive.webpacs} )
<VirtualHost ${pac.curINetAddr.inetAddr} ${pac.curINet6Addr.inetAddr}>
<VirtualHost ${pac.curINetAddr.inet4Addr} ${pac.curINetAddr.inet6Addr}>
DefaultRoot ~ ${pac.name}
ServerName "${pac.name}.hostsharing.net"
AllowOverwrite on

View File

@ -25,7 +25,7 @@ public class PacRemote extends AbstractRemote {
resultMap.put("id", Long.toString(pac.getId()));
resultMap.put("hive", pac.getHiveName());
resultMap.put("customer", pac.getCustomer().getName());
resultMap.put("curinetaddr", pac.getCurINetAddr().getInetAddr());
resultMap.put("curinetaddr", pac.getCurINetAddr().getInet4Addr());
resultMap.put("created", TextUtil.format(pac.getCreated()));
resultMap.put("free", TextUtil.format(pac.isFree()));
Date cancelled = pac.getCancelled();
@ -76,7 +76,7 @@ public class PacRemote extends AbstractRemote {
}
INetAddress curINetAddr = pac.getCurINetAddr();
String inetAddrString = (String) setParams.get("curinetaddr");
if ((curINetAddr == null || curINetAddr.getInetAddr() == null) && assertNotNull(inetAddrString)) {
if ((curINetAddr == null || curINetAddr.getInet4Addr() == null) && assertNotNull(inetAddrString)) {
curINetAddr = new INetAddress(inetAddrString);
pac.setCurINetAddr(curINetAddr);
}