Merge "VOL-434: Introduced configuration parameter to enable changing of src/dst MAC address" into dhcpl2relay-1.1
diff --git a/src/main/java/org/opencord/dhcpl2relay/DhcpL2Relay.java b/src/main/java/org/opencord/dhcpl2relay/DhcpL2Relay.java
index 8911a8f..f941afc 100755
--- a/src/main/java/org/opencord/dhcpl2relay/DhcpL2Relay.java
+++ b/src/main/java/org/opencord/dhcpl2relay/DhcpL2Relay.java
@@ -77,6 +77,7 @@
 import org.slf4j.LoggerFactory;
 
 import java.nio.ByteBuffer;
+import java.util.Arrays;
 import java.util.Dictionary;
 import java.util.Map;
 import java.util.List;
@@ -139,7 +140,7 @@
     protected boolean option82 = true;
 
     @Property(name = "enableDhcpBroadcastReplies", boolValue = false,
-            label = "Add option 82 to relayed packets")
+            label = "Ask the DHCP Server to send back replies as L2 broadcast")
     protected boolean enableDhcpBroadcastReplies = false;
 
     private DhcpRelayPacketProcessor dhcpRelayPacketProcessor =
@@ -203,6 +204,11 @@
         if (o != null) {
             option82 = o;
         }
+
+        o = Tools.isPropertyEnabled(properties, "enableDhcpBroadcastReplies");
+        if (o != null) {
+            enableDhcpBroadcastReplies = o;
+        }
     }
 
     /**
@@ -566,6 +572,10 @@
 
             MacAddress dstMac = valueOf(dhcpPayload.getClientHardwareAddress());
             ConnectPoint subsCp = getConnectPointOfClient(dstMac);
+            // If we can't find the subscriber, can't process further
+            if (subsCp == null) {
+                return null;
+            }
             // if it's an ACK packet store the information for display purpose
             if (getDhcpPacketType(dhcpPayload) == DHCPPacketType.DHCPACK) {
 
@@ -579,7 +589,12 @@
 
                     String circuitId = "None";
                     if (circuitIds.size() == 1) {
-                        circuitId = circuitIds.get(0).getData().toString();
+                        byte[] array = circuitIds.get(0).getData();
+
+                        try {
+                            // we leave the first two bytes as they are the id and length
+                            circuitId = new String(Arrays.copyOfRange(array, 2, array.length), "UTF-8");
+                        } catch (Exception e) { }
                     }
 
                     IpAddress ip = IpAddress.valueOf(dhcpPayload.getYourIPAddress());