fixed bugs in address list configuration and use
authorVictor Kirhenshtein <victor@netxms.org>
Tue, 29 Dec 2015 21:21:58 +0000 (23:21 +0200)
committerVictor Kirhenshtein <victor@netxms.org>
Tue, 29 Dec 2015 21:21:58 +0000 (23:21 +0200)
23 files changed:
ChangeLog
include/netxms-version.h
include/nms_util.h
src/java/client/netxms-client/src/main/java/org/netxms/client/InetAddressListElement.java [new file with mode: 0644]
src/java/client/netxms-client/src/main/java/org/netxms/client/IpAddressListElement.java [deleted file]
src/java/client/netxms-client/src/main/java/org/netxms/client/NXCSession.java
src/java/client/netxms-client/src/main/java/org/netxms/client/ProtocolVersion.java
src/java/netxms-eclipse/ServerConfig/src/org/netxms/ui/eclipse/serverconfig/dialogs/AddAddressListElementDialog.java
src/java/netxms-eclipse/ServerConfig/src/org/netxms/ui/eclipse/serverconfig/views/NetworkDiscoveryConfigurator.java
src/java/netxms-eclipse/ServerConfig/src/org/netxms/ui/eclipse/serverconfig/views/helpers/AddressListElementComparator.java
src/java/netxms-eclipse/ServerConfig/src/org/netxms/ui/eclipse/serverconfig/views/helpers/DiscoveryConfig.java
src/libnetxms/inetaddr.cpp
src/server/core/Makefile.am
src/server/core/addrlist.cpp [new file with mode: 0644]
src/server/core/np.cpp
src/server/core/poll.cpp
src/server/core/session.cpp
src/server/include/nms_core.h
src/server/tools/nxdbmgr/upgrade.cpp
webui/webapp/ServerConfig/src/org/netxms/ui/eclipse/serverconfig/dialogs/AddAddressListElementDialog.java
webui/webapp/ServerConfig/src/org/netxms/ui/eclipse/serverconfig/views/NetworkDiscoveryConfigurator.java
webui/webapp/ServerConfig/src/org/netxms/ui/eclipse/serverconfig/views/helpers/AddressListElementComparator.java
webui/webapp/ServerConfig/src/org/netxms/ui/eclipse/serverconfig/views/helpers/DiscoveryConfig.java

index bd2fc6e..063177c 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -23,6 +23,7 @@
 - Improved agent data cache reconciliation
 - Fixed Oracle 12c compatibility issues
 - Automatic configuration import from templates directory on server startup
+- Fixed address list configuration bug
 - Management console:
        - Object tool input fields can be rearranged
        - Line width can be configured for line charts on dashboards
index e9ce04e..ef1e153 100644 (file)
@@ -48,7 +48,7 @@
 #define CLIENT_PROTOCOL_VERSION_PUSH      1     /* Data push API */
 #define CLIENT_PROTOCOL_VERSION_TRAP      1     /* Event (trap) sending API */
 #define CLIENT_PROTOCOL_VERSION_MOBILE    1     /* All functionality relevant for mobile client */
-#define CLIENT_PROTOCOL_VERSION_FULL      2     /* All functionality */
+#define CLIENT_PROTOCOL_VERSION_FULL      3     /* All functionality */
 
 /**
  * Protocol version positions
index ee4b903..bce7f59 100644 (file)
@@ -1142,6 +1142,7 @@ public:
    int getHostBits() const { return (m_family == AF_INET) ? (32 - m_maskBits) : (128 - m_maskBits); }
 
    InetAddress getSubnetAddress() const;
+   InetAddress getSubnetBroadcast() const;
    bool isSubnetBroadcast(int maskBits) const;
 
    String toString() const;
diff --git a/src/java/client/netxms-client/src/main/java/org/netxms/client/InetAddressListElement.java b/src/java/client/netxms-client/src/main/java/org/netxms/client/InetAddressListElement.java
new file mode 100644 (file)
index 0000000..2791417
--- /dev/null
@@ -0,0 +1,192 @@
+/**
+ * NetXMS - open source network management system
+ * Copyright (C) 2003-2015 Victor Kirhenshtein
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+package org.netxms.client;
+
+import java.net.InetAddress;
+import org.netxms.base.NXCPMessage;
+
+/**
+ * Element of IP address list. Can represent either subnet or address range.
+ */
+public class InetAddressListElement
+{
+       public static final int SUBNET = 0;
+       public static final int RANGE = 1;
+       
+       private int type;
+       private InetAddress baseAddress;
+       private InetAddress endAddress;
+       private int maskBits;
+       
+       /**
+        * Create new "range" element
+        * 
+        * @param baseAddress
+        * @param endAddress
+        */
+       public InetAddressListElement(InetAddress baseAddress, InetAddress endAddress)
+       {
+               this.type = RANGE;
+               this.baseAddress = baseAddress;
+               this.endAddress = endAddress;
+               this.maskBits = 0;
+       }
+
+   /**
+    * Create new "subnet" element
+    * 
+    * @param baseAddress
+    * @param endAddress
+    */
+   public InetAddressListElement(InetAddress baseAddress, int maskBits)
+   {
+      this.type = SUBNET;
+      this.baseAddress = baseAddress;
+      this.endAddress = null;
+      this.maskBits = maskBits;
+   }
+
+       /**
+        * Create element from NXCP message
+        * 
+        * @param msg NXCP message
+        * @param baseId base variable ID
+        */
+       protected InetAddressListElement(NXCPMessage msg, long baseId)
+       {
+               type = msg.getFieldAsInt32(baseId);
+               baseAddress = msg.getFieldAsInetAddress(baseId + 1);
+               if (type == SUBNET)
+               {
+                  maskBits = msg.getFieldAsInt32(baseId + 2);
+                  endAddress = null;
+               }
+               else
+               {
+                  endAddress = msg.getFieldAsInetAddress(baseId + 2);
+                  maskBits = 0;
+               }
+       }
+
+       /**
+        * Fill NXCP message
+        * 
+        * @param msg
+        * @param baseId
+        */
+       public void fillMessage(NXCPMessage msg, long baseId)
+   {
+          msg.setFieldInt16(baseId, type);
+          msg.setField(baseId + 1, baseAddress);
+          if (type == SUBNET)
+             msg.setFieldInt16(baseId + 2, maskBits);
+          else
+             msg.setField(baseId + 2, endAddress);
+   }
+
+       /**
+        * @return the type
+        */
+       public int getType()
+       {
+               return type;
+       }
+
+   /**
+    * @return the baseAddress
+    */
+   public InetAddress getBaseAddress()
+   {
+      return baseAddress;
+   }
+
+   /**
+    * @return the endAddress
+    */
+   public InetAddress getEndAddress()
+   {
+      return endAddress;
+   }
+
+   /**
+    * @return the maskBits
+    */
+   public int getMaskBits()
+   {
+      return maskBits;
+   }
+
+   /* (non-Javadoc)
+    * @see java.lang.Object#toString()
+    */
+   @Override
+   public String toString()
+   {
+      return (type == SUBNET) ? baseAddress.getHostAddress() + "/" + maskBits : baseAddress.getHostAddress() + " - " + endAddress.getHostAddress();
+   }
+
+   /* (non-Javadoc)
+    * @see java.lang.Object#hashCode()
+    */
+   @Override
+   public int hashCode()
+   {
+      final int prime = 31;
+      int result = 1;
+      result = prime * result + ((baseAddress == null) ? 0 : baseAddress.hashCode());
+      result = prime * result + ((endAddress == null) ? 0 : endAddress.hashCode());
+      result = prime * result + maskBits;
+      result = prime * result + type;
+      return result;
+   }
+
+   /* (non-Javadoc)
+    * @see java.lang.Object#equals(java.lang.Object)
+    */
+   @Override
+   public boolean equals(Object obj)
+   {
+      if (this == obj)
+         return true;
+      if (obj == null)
+         return false;
+      if (getClass() != obj.getClass())
+         return false;
+      InetAddressListElement other = (InetAddressListElement)obj;
+      if (baseAddress == null)
+      {
+         if (other.baseAddress != null)
+            return false;
+      }
+      else if (!baseAddress.equals(other.baseAddress))
+         return false;
+      if (endAddress == null)
+      {
+         if (other.endAddress != null)
+            return false;
+      }
+      else if (!endAddress.equals(other.endAddress))
+         return false;
+      if (maskBits != other.maskBits)
+         return false;
+      if (type != other.type)
+         return false;
+      return true;
+   }
+}
diff --git a/src/java/client/netxms-client/src/main/java/org/netxms/client/IpAddressListElement.java b/src/java/client/netxms-client/src/main/java/org/netxms/client/IpAddressListElement.java
deleted file mode 100644 (file)
index 91fa0c3..0000000
+++ /dev/null
@@ -1,134 +0,0 @@
-/**
- * 
- */
-package org.netxms.client;
-
-import java.net.InetAddress;
-import org.netxms.base.NXCPMessage;
-
-/**
- * Element of IP address list. Can represent either subnet or address range.
- */
-public class IpAddressListElement
-{
-       public static final int SUBNET = 0;
-       public static final int RANGE = 1;
-       
-       private int type;
-       private InetAddress addr1;
-       private InetAddress addr2;
-       
-       /**
-        * Create new element
-        * 
-        * @param type
-        * @param addr1
-        * @param addr2
-        */
-       public IpAddressListElement(int type, InetAddress addr1, InetAddress addr2)
-       {
-               this.type = type;
-               this.addr1 = addr1;
-               this.addr2 = addr2;
-       }
-
-       /**
-        * Create element from NXCP message
-        * 
-        * @param msg NXCP message
-        * @param baseId base variable ID
-        */
-       protected IpAddressListElement(NXCPMessage msg, long baseId)
-       {
-               type = msg.getFieldAsInt32(baseId);
-               addr1 = msg.getFieldAsInetAddress(baseId + 1);
-               addr2 = msg.getFieldAsInetAddress(baseId + 2);
-       }
-
-       /**
-        * @return the type
-        */
-       public int getType()
-       {
-               return type;
-       }
-
-       /**
-        * Get first address (subnet base address or range start)
-        * 
-        * @return the addr1
-        */
-       public InetAddress getAddr1()
-       {
-               return addr1;
-       }
-
-       /**
-        * Get second address (subnet mask or range last address)
-        * 
-        * @return the addr2
-        */
-       public InetAddress getAddr2()
-       {
-               return addr2;
-       }
-
-       /* (non-Javadoc)
-        * @see java.lang.Object#toString()
-        */
-       @Override
-       public String toString()
-       {
-               StringBuilder sb = new StringBuilder();
-               sb.append(addr1.getHostAddress());
-               sb.append((type == SUBNET) ? '/' : '-');
-               sb.append(addr2.getHostAddress());
-               return sb.toString();
-       }
-
-       /* (non-Javadoc)
-        * @see java.lang.Object#hashCode()
-        */
-       @Override
-       public int hashCode()
-       {
-               final int prime = 31;
-               int result = 1;
-               result = prime * result + ((addr1 == null) ? 0 : addr1.hashCode());
-               result = prime * result + ((addr2 == null) ? 0 : addr2.hashCode());
-               result = prime * result + type;
-               return result;
-       }
-
-       /* (non-Javadoc)
-        * @see java.lang.Object#equals(java.lang.Object)
-        */
-       @Override
-       public boolean equals(Object obj)
-       {
-               if (this == obj)
-                       return true;
-               if (obj == null)
-                       return false;
-               if (getClass() != obj.getClass())
-                       return false;
-               IpAddressListElement other = (IpAddressListElement)obj;
-               if (addr1 == null)
-               {
-                       if (other.addr1 != null)
-                               return false;
-               }
-               else if (!addr1.equals(other.addr1))
-                       return false;
-               if (addr2 == null)
-               {
-                       if (other.addr2 != null)
-                               return false;
-               }
-               else if (!addr2.equals(other.addr2))
-                       return false;
-               if (type != other.type)
-                       return false;
-               return true;
-       }
-}
index c9075f8..50cee86 100644 (file)
@@ -35,7 +35,6 @@ import java.security.SignatureException;
 import java.security.cert.Certificate;
 import java.security.cert.CertificateEncodingException;
 import java.util.ArrayList;
-import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.Comparator;
@@ -7504,18 +7503,18 @@ public class NXCSession
     * @throws IOException  if socket or file I/O error occurs
     * @throws NXCException if NetXMS server returns an error or operation was timed out
     */
-   public List<IpAddressListElement> getAddressList(int listId) throws IOException, NXCException
+   public List<InetAddressListElement> getAddressList(int listId) throws IOException, NXCException
    {
       final NXCPMessage msg = newMessage(NXCPCodes.CMD_GET_ADDR_LIST);
       msg.setFieldInt32(NXCPCodes.VID_ADDR_LIST_TYPE, listId);
       sendMessage(msg);
       final NXCPMessage response = waitForRCC(msg.getMessageId());
       int count = response.getFieldAsInt32(NXCPCodes.VID_NUM_RECORDS);
-      final List<IpAddressListElement> list = new ArrayList<IpAddressListElement>(count);
+      final List<InetAddressListElement> list = new ArrayList<InetAddressListElement>(count);
       long varId = NXCPCodes.VID_ADDR_LIST_BASE;
       for(int i = 0; i < count; i++)
       {
-         list.add(new IpAddressListElement(response, varId));
+         list.add(new InetAddressListElement(response, varId));
          varId += 10;
       }
       return list;
@@ -7529,18 +7528,16 @@ public class NXCSession
     * @throws IOException  if socket or file I/O error occurs
     * @throws NXCException if NetXMS server returns an error or operation was timed out
     */
-   public void setAddressList(int listId, List<IpAddressListElement> list) throws IOException, NXCException
+   public void setAddressList(int listId, List<InetAddressListElement> list) throws IOException, NXCException
    {
       final NXCPMessage msg = newMessage(NXCPCodes.CMD_SET_ADDR_LIST);
       msg.setFieldInt32(NXCPCodes.VID_ADDR_LIST_TYPE, listId);
       msg.setFieldInt32(NXCPCodes.VID_NUM_RECORDS, list.size());
-      long varId = NXCPCodes.VID_ADDR_LIST_BASE;
-      for(IpAddressListElement e : list)
+      long fieldId = NXCPCodes.VID_ADDR_LIST_BASE;
+      for(InetAddressListElement e : list)
       {
-         msg.setFieldInt32(varId++, e.getType());
-         msg.setField(varId++, e.getAddr1());
-         msg.setField(varId++, e.getAddr2());
-         varId += 7;
+         e.fillMessage(msg, fieldId);
+         fieldId += 10;
       }
       sendMessage(msg);
       waitForRCC(msg.getMessageId());
index 47a73b8..a9f24a5 100644 (file)
@@ -33,7 +33,7 @@ public final class ProtocolVersion
    public static final int PUSH = 1;
    public static final int TRAP = 1;
    public static final int MOBILE = 1;
-   public static final int FULL = 2;
+   public static final int FULL = 3;
    
    // Indexes
    public static final int INDEX_BASE = 0;
index d95398b..162cc43 100644 (file)
@@ -18,6 +18,8 @@
  */
 package org.netxms.ui.eclipse.serverconfig.dialogs;
 
+import java.net.Inet4Address;
+import java.net.Inet6Address;
 import java.net.InetAddress;
 import java.net.UnknownHostException;
 import org.eclipse.jface.dialogs.Dialog;
@@ -30,7 +32,7 @@ import org.eclipse.swt.widgets.Button;
 import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.Control;
 import org.eclipse.swt.widgets.Shell;
-import org.netxms.client.IpAddressListElement;
+import org.netxms.client.InetAddressListElement;
 import org.netxms.ui.eclipse.serverconfig.Messages;
 import org.netxms.ui.eclipse.tools.MessageDialogHelper;
 import org.netxms.ui.eclipse.tools.WidgetHelper;
@@ -45,9 +47,7 @@ public class AddAddressListElementDialog extends Dialog
        private Button radioRange;
        private LabeledText textAddr1;
        private LabeledText textAddr2;
-       private InetAddress address1;
-       private InetAddress address2;
-       private int type;
+       private InetAddressListElement element;
        
        /**
         * @param parentShell
@@ -127,7 +127,7 @@ public class AddAddressListElementDialog extends Dialog
                
                textAddr2 = new LabeledText(dialogArea, SWT.NONE);
                textAddr2.setLabel(Messages.get().AddAddressListElementDialog_NetMask);
-               textAddr2.setText("255.255.255.0"); //$NON-NLS-1$
+               textAddr2.setText("0"); //$NON-NLS-1$
                gd = new GridData();
                gd.horizontalAlignment = SWT.FILL;
                gd.grabExcessHorizontalSpace = true;
@@ -142,41 +142,41 @@ public class AddAddressListElementDialog extends Dialog
        @Override
        protected void okPressed()
        {
-               type = radioSubnet.getSelection() ? IpAddressListElement.SUBNET : IpAddressListElement.RANGE;
                try
                {
-                       address1 = InetAddress.getByName(textAddr1.getText());
-                       address2 = InetAddress.getByName(textAddr2.getText());
+             if (radioSubnet.getSelection())
+             {
+                InetAddress baseAddress = InetAddress.getByName(textAddr1.getText().trim());
+                int maskBits = Integer.parseInt(textAddr2.getText().trim());
+                if ((maskBits < 0) ||
+                    ((baseAddress instanceof Inet4Address) && (maskBits > 32)) ||
+                ((baseAddress instanceof Inet6Address) && (maskBits > 128)))
+                   throw new NumberFormatException("Invalid network mask");
+                element = new InetAddressListElement(baseAddress, maskBits);
+             }
+             else
+             {
+            element = new InetAddressListElement(InetAddress.getByName(textAddr1.getText().trim()), InetAddress.getByName(textAddr2.getText().trim()));
+             }
                }
                catch(UnknownHostException e)
                {
                        MessageDialogHelper.openWarning(getShell(), Messages.get().AddAddressListElementDialog_Warning, Messages.get().AddAddressListElementDialog_EnterValidData);
                        return;
                }
+      catch(NumberFormatException e)
+      {
+         MessageDialogHelper.openWarning(getShell(), Messages.get().AddAddressListElementDialog_Warning, Messages.get().AddAddressListElementDialog_EnterValidData);
+         return;
+      }
                super.okPressed();
        }
 
-       /**
-        * @return the address1
-        */
-       public InetAddress getAddress1()
-       {
-               return address1;
-       }
-
-       /**
-        * @return the address2
-        */
-       public InetAddress getAddress2()
-       {
-               return address2;
-       }
-
-       /**
-        * @return the type
-        */
-       public int getType()
-       {
-               return type;
-       }
+   /**
+    * @return the element
+    */
+   public InetAddressListElement getElement()
+   {
+      return element;
+   }
 }
index d78ff82..c66d463 100644 (file)
@@ -51,7 +51,7 @@ import org.eclipse.ui.forms.widgets.Section;
 import org.eclipse.ui.forms.widgets.TableWrapData;
 import org.eclipse.ui.forms.widgets.TableWrapLayout;
 import org.eclipse.ui.part.ViewPart;
-import org.netxms.client.IpAddressListElement;
+import org.netxms.client.InetAddressListElement;
 import org.netxms.client.constants.NetworkDiscovery;
 import org.netxms.ui.eclipse.console.resources.SharedIcons;
 import org.netxms.ui.eclipse.jobs.ConsoleJob;
@@ -682,8 +682,8 @@ public class NetworkDiscoveryConfigurator extends ViewPart implements ISaveableP
       AddAddressListElementDialog dlg = new AddAddressListElementDialog(getSite().getShell());
       if (dlg.open() == Window.OK)
       {
-         final List<IpAddressListElement> list = config.getTargets();
-         IpAddressListElement element = new IpAddressListElement(dlg.getType(), dlg.getAddress1(), dlg.getAddress2());
+         final List<InetAddressListElement> list = config.getTargets();
+         InetAddressListElement element = dlg.getElement();
          if (!list.contains(element))
          {
             list.add(element);
@@ -698,7 +698,7 @@ public class NetworkDiscoveryConfigurator extends ViewPart implements ISaveableP
     */
    private void removeTargetAddressListElements()
    {
-      final List<IpAddressListElement> list = config.getTargets();
+      final List<InetAddressListElement> list = config.getTargets();
       IStructuredSelection selection = (IStructuredSelection)activeDiscoveryAddressList.getSelection();
       if (selection.size() > 0)
       {
@@ -719,8 +719,8 @@ public class NetworkDiscoveryConfigurator extends ViewPart implements ISaveableP
       AddAddressListElementDialog dlg = new AddAddressListElementDialog(getSite().getShell());
       if (dlg.open() == Window.OK)
       {
-         final List<IpAddressListElement> list = config.getAddressFilter();
-         IpAddressListElement element = new IpAddressListElement(dlg.getType(), dlg.getAddress1(), dlg.getAddress2());
+         final List<InetAddressListElement> list = config.getAddressFilter();
+         InetAddressListElement element = dlg.getElement();
          if (!list.contains(element))
          {
             list.add(element);
@@ -735,7 +735,7 @@ public class NetworkDiscoveryConfigurator extends ViewPart implements ISaveableP
     */
    private void removeAddressFilterElements()
    {
-      final List<IpAddressListElement> list = config.getAddressFilter();
+      final List<InetAddressListElement> list = config.getAddressFilter();
       IStructuredSelection selection = (IStructuredSelection)filterAddressList.getSelection();
       if (selection.size() > 0)
       {
index 43531dd..5efd463 100644 (file)
@@ -9,7 +9,7 @@ import org.eclipse.jface.viewers.TableViewer;
 import org.eclipse.jface.viewers.Viewer;
 import org.eclipse.jface.viewers.ViewerComparator;
 import org.eclipse.swt.SWT;
-import org.netxms.client.IpAddressListElement;
+import org.netxms.client.InetAddressListElement;
 
 /**
  * Comparator for address list elements
@@ -22,13 +22,17 @@ public class AddressListElementComparator extends ViewerComparator
        @Override
        public int compare(Viewer viewer, Object e1, Object e2)
        {
-               IpAddressListElement a1 = (IpAddressListElement)e1;
-               IpAddressListElement a2 = (IpAddressListElement)e2;
+               InetAddressListElement a1 = (InetAddressListElement)e1;
+               InetAddressListElement a2 = (InetAddressListElement)e2;
                
-               int rc = compareIpAddresses(a1.getAddr1(), a2.getAddr1());
+               int rc = compareIpAddresses(a1.getBaseAddress(), a2.getBaseAddress());
                if (rc == 0)
                {
-                       rc = compareIpAddresses(a1.getAddr2(), a2.getAddr2());
+                  rc = a1.getType() - a2.getType();
+                  if (rc == 0)
+                  {
+                     rc = (a1.getType() == InetAddressListElement.SUBNET) ? a1.getMaskBits() - a2.getMaskBits() : compareIpAddresses(a1.getEndAddress(), a2.getEndAddress());
+                  }
                }
                
                int dir = ((TableViewer)viewer).getTable().getSortDirection();
@@ -46,10 +50,14 @@ public class AddressListElementComparator extends ViewerComparator
        {
                byte[] b1 = a1.getAddress();
                byte[] b2 = a2.getAddress();
+
+               int rc = b1.length - b2.length;
+               if (rc != 0)
+                  return rc;
                
                for(int i = 0; i < b1.length; i++)
                {
-                       int rc = b1[i] - b2[i];
+                       rc = ((int)b1[i] & 0xFF) - ((int)b2[i] & 0xFF);
                        if (rc != 0)
                                return Integer.signum(rc);
                }
index 526792c..7be6054 100644 (file)
@@ -6,7 +6,7 @@ package org.netxms.ui.eclipse.serverconfig.views.helpers;
 import java.io.IOException;
 import java.util.List;
 import java.util.Map;
-import org.netxms.client.IpAddressListElement;
+import org.netxms.client.InetAddressListElement;
 import org.netxms.client.NXCException;
 import org.netxms.client.NXCSession;
 import org.netxms.client.server.ServerVariable;
@@ -22,8 +22,8 @@ public class DiscoveryConfig
        private boolean useSnmpTraps;
        private int filterFlags;
        private String filter;
-       private List<IpAddressListElement> targets;
-       private List<IpAddressListElement> addressFilter;
+       private List<InetAddressListElement> targets;
+       private List<InetAddressListElement> addressFilter;
        
        /**
         * Create empty object
@@ -211,7 +211,7 @@ public class DiscoveryConfig
        /**
         * @return the targets
         */
-       public List<IpAddressListElement> getTargets()
+       public List<InetAddressListElement> getTargets()
        {
                return targets;
        }
@@ -219,7 +219,7 @@ public class DiscoveryConfig
        /**
         * @param targets the targets to set
         */
-       public void setTargets(List<IpAddressListElement> targets)
+       public void setTargets(List<InetAddressListElement> targets)
        {
                this.targets = targets;
        }
@@ -227,7 +227,7 @@ public class DiscoveryConfig
        /**
         * @return the addressFilter
         */
-       public List<IpAddressListElement> getAddressFilter()
+       public List<InetAddressListElement> getAddressFilter()
        {
                return addressFilter;
        }
@@ -235,7 +235,7 @@ public class DiscoveryConfig
        /**
         * @param addressFilter the addressFilter to set
         */
-       public void setAddressFilter(List<IpAddressListElement> addressFilter)
+       public void setAddressFilter(List<InetAddressListElement> addressFilter)
        {
                this.addressFilter = addressFilter;
        }
index 37d8ec1..37291c6 100644 (file)
@@ -206,6 +206,19 @@ InetAddress InetAddress::getSubnetAddress() const
 }
 
 /**
+ * Get corresponding subnet broadcast address for this InetAddress
+ */
+InetAddress InetAddress::getSubnetBroadcast() const
+{
+   InetAddress addr(*this);
+   if ((m_family == AF_INET) && (m_maskBits < 32))
+   {
+      addr.m_addr.v4 = m_addr.v4 | (0xFFFFFFFF >> m_maskBits);
+   }
+   return addr;
+}
+
+/**
  * Check if this address is a subnet broadcast for given subnet mask length
  */
 bool InetAddress::isSubnetBroadcast(int maskBits) const
index 4a24301..8ccad6f 100644 (file)
@@ -1,8 +1,8 @@
 # vim:ts=3:sw=3
 
 lib_LTLIBRARIES = libnxcore.la
-libnxcore_la_SOURCES =  accesspoint.cpp acl.cpp actions.cpp admin.cpp \
-                       agent.cpp agent_policy.cpp alarm.cpp audit.cpp \
+libnxcore_la_SOURCES =  accesspoint.cpp acl.cpp actions.cpp addrlist.cpp \
+                       admin.cpp agent.cpp agent_policy.cpp alarm.cpp audit.cpp \
                        ap_config.cpp ap_jobs.cpp beacon.cpp bizservice.cpp \
                        bizsvcroot.cpp bridge.cpp cas_validator.cpp cdp.cpp \
                        cert.cpp client.cpp cluster.cpp columnfilter.cpp \
diff --git a/src/server/core/addrlist.cpp b/src/server/core/addrlist.cpp
new file mode 100644 (file)
index 0000000..d095238
--- /dev/null
@@ -0,0 +1,191 @@
+/*
+** NetXMS - Network Management System
+** Copyright (C) 2003-2015 Victor Kirhenshtein
+**
+** This program is free software; you can redistribute it and/or modify
+** it under the terms of the GNU General Public License as published by
+** the Free Software Foundation; either version 2 of the License, or
+** (at your option) any later version.
+**
+** This program is distributed in the hope that it will be useful,
+** but WITHOUT ANY WARRANTY; without even the implied warranty of
+** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+** GNU General Public License for more details.
+**
+** You should have received a copy of the GNU General Public License
+** along with this program; if not, write to the Free Software
+** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+**
+** File: addrlist.cpp
+**
+**/
+
+#include "nxcore.h"
+
+/**
+ * Create address list element from NXCP message
+ */
+InetAddressListElement::InetAddressListElement(NXCPMessage *msg, UINT32 baseId)
+{
+   m_type = msg->getFieldAsInt16(baseId);
+   m_baseAddress = msg->getFieldAsInetAddress(baseId + 1);
+   if (m_type == InetAddressListElement_SUBNET)
+   {
+      m_baseAddress.setMaskBits(msg->getFieldAsInt16(baseId + 2));
+   }
+   else
+   {
+      m_endAddress = msg->getFieldAsInetAddress(baseId + 2);
+   }
+}
+
+/**
+ * Create new "range" type address list element
+ */
+InetAddressListElement::InetAddressListElement(const InetAddress& baseAddr, const InetAddress& endAddr)
+{
+   m_type = InetAddressListElement_RANGE;
+   m_baseAddress = baseAddr;
+   m_endAddress = endAddr;
+}
+
+/**
+ * Create new "subnet" type address list element
+ */
+InetAddressListElement::InetAddressListElement(const InetAddress& baseAddr, int maskBits)
+{
+   m_type = InetAddressListElement_SUBNET;
+   m_baseAddress = baseAddr;
+   m_baseAddress.setMaskBits(maskBits);
+}
+
+/**
+ * Create address list element from DB record
+ * Expected field order: addr_type,addr1,addr2
+ */
+InetAddressListElement::InetAddressListElement(DB_RESULT hResult, int row)
+{
+   m_type = DBGetFieldLong(hResult, row, 0);
+   m_baseAddress = DBGetFieldInetAddr(hResult, row, 1);
+   if (m_type == InetAddressListElement_SUBNET)
+   {
+      // mask field can be represented as bit count or as IPv4 mask (like 255.255.255.0)
+      TCHAR mask[64];
+      DBGetField(hResult, row, 2, mask, 64);
+
+      TCHAR *eptr;
+      int bits = _tcstol(mask, &eptr, 10);
+      if ((bits != 0) && (*eptr == 0))
+      {
+         m_baseAddress.setMaskBits(bits);
+      }
+      else if (m_baseAddress.getFamily() == AF_INET)
+      {
+         InetAddress a = InetAddress::parse(mask);
+         if (a.getFamily() == AF_INET)
+         {
+            m_baseAddress.setMaskBits(BitsInMask(a.getAddressV4()));
+         }
+      }
+   }
+   else
+   {
+      m_endAddress = DBGetFieldInetAddr(hResult, row, 2);
+   }
+}
+
+/**
+ * Fill NXCP message
+ */
+void InetAddressListElement::fillMessage(NXCPMessage *msg, UINT32 baseId) const
+{
+   msg->setField(baseId, (INT16)m_type);
+   msg->setField(baseId + 1, m_baseAddress);
+   if (m_type == InetAddressListElement_SUBNET)
+      msg->setField(baseId + 2, (INT16)m_baseAddress.getMaskBits());
+   else
+      msg->setField(baseId + 2, m_endAddress);
+}
+
+/**
+ * Check if element contains given address
+ */
+bool InetAddressListElement::contains(const InetAddress& addr) const
+{
+   if (m_type == InetAddressListElement_SUBNET)
+      return m_baseAddress.contain(addr);
+   if ((m_baseAddress.getFamily() == addr.getFamily()) && (m_endAddress.getFamily() == addr.getFamily()))
+      return (m_baseAddress.compareTo(addr) <= 0) && (m_endAddress.compareTo(addr) >= 0);
+   return false;
+}
+
+/**
+ * Convert to text representation
+ */
+String InetAddressListElement::toString() const
+{
+   String s = m_baseAddress.toString();
+   if (m_type == InetAddressListElement_SUBNET)
+   {
+      s.append(_T('/'));
+      s.append(m_baseAddress.getMaskBits());
+   }
+   else
+   {
+      s.append(_T('-'));
+      s.append(m_endAddress.toString());
+   }
+   return s;
+}
+
+/**
+ * Update address list from NXCP message
+ */
+bool UpdateAddressListFromMessage(NXCPMessage *msg)
+{
+   DB_HANDLE hdb = DBConnectionPoolAcquireConnection();
+
+   int listType = msg->getFieldAsInt32(VID_ADDR_LIST_TYPE);
+   TCHAR query[256];
+   _sntprintf(query, 256, _T("DELETE FROM address_lists WHERE list_type=%d"), listType);
+
+   DBBegin(hdb);
+   bool success = DBQuery(hdb, query);
+   if (success)
+   {
+      int count = msg->getFieldAsInt32(VID_NUM_RECORDS);
+      UINT32 fieldId = VID_ADDR_LIST_BASE;
+      for(int i = 0; (i < count) && success; i++, fieldId += 10)
+      {
+         InetAddressListElement e = InetAddressListElement(msg, fieldId);
+         if (e.getType() == InetAddressListElement_SUBNET)
+         {
+            TCHAR baseAddr[64];
+            _sntprintf(query, 256, _T("INSERT INTO address_lists (list_type,addr_type,addr1,addr2,community_id) VALUES (%d,%d,'%s','%d',0)"),
+                       listType, e.getType(), e.getBaseAddress().toString(baseAddr), e.getBaseAddress().getMaskBits());
+         }
+         else
+         {
+            TCHAR baseAddr[64], endAddr[64];
+            _sntprintf(query, 256, _T("INSERT INTO address_lists (list_type,addr_type,addr1,addr2,community_id) VALUES (%d,%d,'%s','%s',0)"),
+                       listType, e.getType(), e.getBaseAddress().toString(baseAddr), e.getEndAddress().toString(endAddr));
+         }
+         success = DBQuery(hdb, query);
+      }
+
+      if (success)
+      {
+         DBCommit(hdb);
+      }
+      else
+      {
+         DBRollback(hdb);
+      }
+   }
+   else
+   {
+      DBRollback(hdb);
+   }
+   DBConnectionPoolReleaseConnection(hdb);
+   return success;
+}
index 4983a7a..364a246 100644 (file)
@@ -505,24 +505,7 @@ static BOOL AcceptNewNode(const InetAddress& addr, UINT32 zoneId, BYTE *macAddr)
             int nRows = DBGetNumRows(hResult);
             for(int i = 0; (i < nRows) && (!bResult); i++)
             {
-               int nType = DBGetFieldLong(hResult, i, 0);
-               if (nType == 0)
-               {
-                  // Subnet
-                  InetAddress subnet = DBGetFieldInetAddr(hResult, i, 1);
-                  subnet.setMaskBits(DBGetFieldLong(hResult, i, 2));
-                  bResult = subnet.contain(data.ipAddr);
-               }
-               else
-               {
-                  // Range
-                  InetAddress addr1 = DBGetFieldInetAddr(hResult, i, 1);
-                  InetAddress addr2 = DBGetFieldInetAddr(hResult, i, 2);
-                  if ((addr1.getFamily() == data.ipAddr.getFamily()) && (addr2.getFamily() == data.ipAddr.getFamily()))
-                     bResult = (addr1.compareTo(data.ipAddr) <= 0) && (addr2.compareTo(data.ipAddr) >= 0);
-                  else
-                     bResult = FALSE;
-               }
+               bResult = InetAddressListElement(hResult, i).contains(data.ipAddr);
             }
             DBFreeResult(hResult);
          }
index 6fcd664..9a76425 100644 (file)
@@ -370,18 +370,24 @@ static void DiscoveryPoller(void *arg)
 /**
  * Check given address range with ICMP ping for new nodes
  */
-static void CheckRange(int nType, UINT32 addr1, UINT32 addr2)
+static void CheckRange(const InetAddressListElement& range)
 {
-   UINT32 from, to;
-   if (nType == 0)
+   if (range.getBaseAddress().getFamily() != AF_INET)
    {
-      from = (addr1 & addr2) + 1;
-      to = from | ~addr2 - 1;
+      DbgPrintf(4, _T("Active discovery on range %s skipped - only IPv4 ranges supported"), (const TCHAR *)range.toString());
+      return;
+   }
+
+   UINT32 from = range.getBaseAddress().getAddressV4();
+   UINT32 to;
+   if (range.getType() == InetAddressListElement_SUBNET)
+   {
+      from++;
+      to = range.getBaseAddress().getSubnetBroadcast().getAddressV4() - 1;
    }
    else
    {
-      from = addr1;
-      to = addr2;
+      to = range.getEndAddress().getAddressV4();
    }
 
    TCHAR ipAddr1[16], ipAddr2[16];
@@ -456,9 +462,7 @@ static THREAD_RESULT THREAD_CALL ActiveDiscoveryPoller(void *arg)
          int nRows = DBGetNumRows(hResult);
          for(int i = 0; (i < nRows) && !IsShutdownInProgress(); i++)
          {
-            CheckRange(DBGetFieldLong(hResult, i, 0),
-                       DBGetFieldIPAddr(hResult, i, 1),
-                       DBGetFieldIPAddr(hResult, i, 2));
+            CheckRange(InetAddressListElement(hResult, i));
          }
          DBFreeResult(hResult);
       }
index 557731c..88ff867 100644 (file)
@@ -71,6 +71,7 @@ void UnregisterClientSession(int id);
 void ResetDiscoveryPoller();
 NXCPMessage *ForwardMessageToReportingServer(NXCPMessage *request, ClientSession *session);
 void RemovePendingFileTransferRequests(ClientSession *session);
+bool UpdateAddressListFromMessage(NXCPMessage *msg);
 
 /**
  * Node poller start data
@@ -9545,31 +9546,29 @@ void ClientSession::pushDCIData(NXCPMessage *pRequest)
 /**
  * Get address list
  */
-void ClientSession::getAddrList(NXCPMessage *pRequest)
+void ClientSession::getAddrList(NXCPMessage *request)
 {
    NXCPMessage msg;
-   TCHAR szQuery[256];
-   UINT32 i, dwNumRec, dwId;
-   DB_RESULT hResult;
-
    msg.setCode(CMD_REQUEST_COMPLETED);
-   msg.setId(pRequest->getId());
+   msg.setId(request->getId());
 
    if (m_dwSystemAccess & SYSTEM_ACCESS_SERVER_CONFIG)
    {
       DB_HANDLE hdb = DBConnectionPoolAcquireConnection();
-      _sntprintf(szQuery, sizeof(szQuery) / sizeof(TCHAR), _T("SELECT addr_type,addr1,addr2 FROM address_lists WHERE list_type=%d"),
-                pRequest->getFieldAsUInt32(VID_ADDR_LIST_TYPE));
-      hResult = DBSelect(hdb, szQuery);
+
+      TCHAR query[256];
+      _sntprintf(query, 256, _T("SELECT addr_type,addr1,addr2 FROM address_lists WHERE list_type=%d"), request->getFieldAsInt32(VID_ADDR_LIST_TYPE));
+      DB_RESULT hResult = DBSelect(hdb, query);
       if (hResult != NULL)
       {
-         dwNumRec = DBGetNumRows(hResult);
-         msg.setField(VID_NUM_RECORDS, dwNumRec);
-         for(i = 0, dwId = VID_ADDR_LIST_BASE; i < dwNumRec; i++, dwId += 7)
+         int count = DBGetNumRows(hResult);
+         msg.setField(VID_NUM_RECORDS, (INT32)count);
+
+         UINT32 fieldId = VID_ADDR_LIST_BASE;
+         for(int i = 0; i < count; i++)
          {
-            msg.setField(dwId++, DBGetFieldULong(hResult, i, 0));
-            msg.setField(dwId++, DBGetFieldIPAddr(hResult, i, 1));
-            msg.setField(dwId++, DBGetFieldIPAddr(hResult, i, 2));
+            InetAddressListElement(hResult, i).fillMessage(&msg, fieldId);
+            fieldId += 10;
          }
          DBFreeResult(hResult);
          msg.setField(VID_RCC, RCC_SUCCESS);
@@ -9591,55 +9590,29 @@ void ClientSession::getAddrList(NXCPMessage *pRequest)
 /**
  * Set address list
  */
-void ClientSession::setAddrList(NXCPMessage *pRequest)
+void ClientSession::setAddrList(NXCPMessage *request)
 {
    NXCPMessage msg;
-   UINT32 i, dwId, dwNumRec, dwListType;
-   TCHAR szQuery[256], szIpAddr1[24], szIpAddr2[24];
-
    msg.setCode(CMD_REQUEST_COMPLETED);
-   msg.setId(pRequest->getId());
+   msg.setId(request->getId());
 
+   int listType = request->getFieldAsInt32(VID_ADDR_LIST_TYPE);
    if (m_dwSystemAccess & SYSTEM_ACCESS_SERVER_CONFIG)
    {
-      DB_HANDLE hdb = DBConnectionPoolAcquireConnection();
-      dwListType = pRequest->getFieldAsUInt32(VID_ADDR_LIST_TYPE);
-      _sntprintf(szQuery, sizeof(szQuery) / sizeof(TCHAR), _T("DELETE FROM address_lists WHERE list_type=%d"), dwListType);
-      DBBegin(hdb);
-      if (DBQuery(hdb, szQuery))
+      if (UpdateAddressListFromMessage(request))
       {
-         dwNumRec = pRequest->getFieldAsUInt32(VID_NUM_RECORDS);
-         for(i = 0, dwId = VID_ADDR_LIST_BASE; i < dwNumRec; i++, dwId += 10)
-         {
-            _sntprintf(szQuery, sizeof(szQuery) / sizeof(TCHAR), _T("INSERT INTO address_lists (list_type,addr_type,addr1,addr2,community_id) VALUES (%d,%d,'%s','%s',0)"),
-                      dwListType, pRequest->getFieldAsUInt32(dwId),
-                      IpToStr(pRequest->getFieldAsUInt32(dwId + 1), szIpAddr1),
-                      IpToStr(pRequest->getFieldAsUInt32(dwId + 2), szIpAddr2));
-            if (!DBQuery(hdb, szQuery))
-               break;
-         }
-
-         if (i == dwNumRec)
-         {
-            DBCommit(hdb);
-            msg.setField(VID_RCC, RCC_SUCCESS);
-         }
-         else
-         {
-            DBRollback(hdb);
-            msg.setField(VID_RCC, RCC_DB_FAILURE);
-         }
+         msg.setField(VID_RCC, RCC_SUCCESS);
+         WriteAuditLog(AUDIT_SYSCFG, true, m_dwUserId, m_workstation, m_id, 0, _T("Address list %d modified"), listType);
       }
       else
       {
-         DBRollback(hdb);
          msg.setField(VID_RCC, RCC_DB_FAILURE);
       }
-      DBConnectionPoolReleaseConnection(hdb);
    }
    else
    {
       msg.setField(VID_RCC, RCC_ACCESS_DENIED);
+      WriteAuditLog(AUDIT_SYSCFG, false, m_dwUserId, m_workstation, m_id, 0, _T("Access denied on modify address list %d"), listType);
    }
 
    sendMessage(&msg);
index f5b3a2e..86244cb 100644 (file)
@@ -263,6 +263,39 @@ typedef struct
 #define NNF_IS_LLDP           0x0080
 
 /**
+ * Address list element types
+ */
+#define InetAddressListElement_SUBNET     0
+#define InetAddressListElement_RANGE      1
+
+/**
+ * IP address list element
+ */
+class NXCORE_EXPORTABLE InetAddressListElement
+{
+private:
+   int m_type;
+   InetAddress m_baseAddress;
+   InetAddress m_endAddress;
+
+public:
+   InetAddressListElement(NXCPMessage *msg, UINT32 baseId);
+   InetAddressListElement(const InetAddress& baseAddr, const InetAddress& endAddr);
+   InetAddressListElement(const InetAddress& baseAddr, int maskBits);
+   InetAddressListElement(DB_RESULT hResult, int row);
+
+   void fillMessage(NXCPMessage *msg, UINT32 baseId) const;
+
+   bool contains(const InetAddress& addr) const;
+
+   int getType() const { return m_type; }
+   const InetAddress& getBaseAddress() const { return m_baseAddress; }
+   const InetAddress& getEndAddress() const { return m_endAddress; }
+
+   String toString() const;
+};
+
+/**
  * Node information for autodiscovery filter
  */
 typedef struct
@@ -584,8 +617,8 @@ private:
    void SendObjectComments(NXCPMessage *pRequest);
    void updateObjectComments(NXCPMessage *pRequest);
    void pushDCIData(NXCPMessage *pRequest);
-   void getAddrList(NXCPMessage *pRequest);
-   void setAddrList(NXCPMessage *pRequest);
+   void getAddrList(NXCPMessage *request);
+   void setAddrList(NXCPMessage *request);
    void resetComponent(NXCPMessage *pRequest);
    void getDCIEventList(NXCPMessage *request);
    void getDCIScriptList(NXCPMessage *request);
index 521af83..9e85186 100644 (file)
@@ -1573,18 +1573,18 @@ static BOOL H_UpgradeFromV345(int currVersion, int newVersion)
    CHK_EXEC(ConvertNetMasks(_T("interfaces"), _T("ip_netmask"), _T("id")));
    CHK_EXEC(ConvertNetMasks(_T("vpn_connector_networks"), _T("ip_netmask"), _T("vpn_id"), _T("ip_addr")));
 
-   DB_RESULT hResult = SQLSelect(_T("SELECT community_id,addr_type,addr1,addr2 FROM address_lists WHERE list_type=0"));
+   DB_RESULT hResult = SQLSelect(_T("SELECT community_id,list_type,addr1,addr2 FROM address_lists WHERE addr_type=0"));
    if (hResult != NULL)
    {
       int count = DBGetNumRows(hResult);
       if (count > 0)
       {
-         CHK_EXEC(SQLQuery(_T("DELETE FROM address_lists WHERE list_type=0")));
+         CHK_EXEC(SQLQuery(_T("DELETE FROM address_lists WHERE addr_type=0")));
 
          for(int i = 0; i < count; i++)
          {
             TCHAR query[256], addr[64];
-            _sntprintf(query, 256, _T("INSERT INTO address_lists (list_type,community_id,addr_type,addr1,addr2) VALUES (0,%d,%d,'%s','%d')"),
+            _sntprintf(query, 256, _T("INSERT INTO address_lists (addr_type,community_id,list_type,addr1,addr2) VALUES (0,%d,%d,'%s','%d')"),
                DBGetFieldLong(hResult, i, 0), DBGetFieldLong(hResult, i, 1), DBGetField(hResult, i, 2, addr, 64),
                BitsInMask(DBGetFieldIPAddr(hResult, i, 3)));
             CHK_EXEC(SQLQuery(query));
@@ -6018,11 +6018,9 @@ static BOOL H_UpgradeFromV75(int currVersion, int newVersion)
    return TRUE;
 }
 
-
-//
-// Upgrade from V74 to V75
-//
-
+/**
+ * Upgrade from V74 to V75
+ */
 static BOOL H_UpgradeFromV74(int currVersion, int newVersion)
 {
    static TCHAR m_szBatch[] =
@@ -6056,11 +6054,9 @@ static BOOL H_UpgradeFromV74(int currVersion, int newVersion)
    return TRUE;
 }
 
-
-//
-// Upgrade from V73 to V74
-//
-
+/**
+ * Upgrade from V73 to V74
+ */
 static BOOL H_UpgradeFromV73(int currVersion, int newVersion)
 {
    static TCHAR m_szBatch[] =
index d95398b..162cc43 100644 (file)
@@ -18,6 +18,8 @@
  */
 package org.netxms.ui.eclipse.serverconfig.dialogs;
 
+import java.net.Inet4Address;
+import java.net.Inet6Address;
 import java.net.InetAddress;
 import java.net.UnknownHostException;
 import org.eclipse.jface.dialogs.Dialog;
@@ -30,7 +32,7 @@ import org.eclipse.swt.widgets.Button;
 import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.Control;
 import org.eclipse.swt.widgets.Shell;
-import org.netxms.client.IpAddressListElement;
+import org.netxms.client.InetAddressListElement;
 import org.netxms.ui.eclipse.serverconfig.Messages;
 import org.netxms.ui.eclipse.tools.MessageDialogHelper;
 import org.netxms.ui.eclipse.tools.WidgetHelper;
@@ -45,9 +47,7 @@ public class AddAddressListElementDialog extends Dialog
        private Button radioRange;
        private LabeledText textAddr1;
        private LabeledText textAddr2;
-       private InetAddress address1;
-       private InetAddress address2;
-       private int type;
+       private InetAddressListElement element;
        
        /**
         * @param parentShell
@@ -127,7 +127,7 @@ public class AddAddressListElementDialog extends Dialog
                
                textAddr2 = new LabeledText(dialogArea, SWT.NONE);
                textAddr2.setLabel(Messages.get().AddAddressListElementDialog_NetMask);
-               textAddr2.setText("255.255.255.0"); //$NON-NLS-1$
+               textAddr2.setText("0"); //$NON-NLS-1$
                gd = new GridData();
                gd.horizontalAlignment = SWT.FILL;
                gd.grabExcessHorizontalSpace = true;
@@ -142,41 +142,41 @@ public class AddAddressListElementDialog extends Dialog
        @Override
        protected void okPressed()
        {
-               type = radioSubnet.getSelection() ? IpAddressListElement.SUBNET : IpAddressListElement.RANGE;
                try
                {
-                       address1 = InetAddress.getByName(textAddr1.getText());
-                       address2 = InetAddress.getByName(textAddr2.getText());
+             if (radioSubnet.getSelection())
+             {
+                InetAddress baseAddress = InetAddress.getByName(textAddr1.getText().trim());
+                int maskBits = Integer.parseInt(textAddr2.getText().trim());
+                if ((maskBits < 0) ||
+                    ((baseAddress instanceof Inet4Address) && (maskBits > 32)) ||
+                ((baseAddress instanceof Inet6Address) && (maskBits > 128)))
+                   throw new NumberFormatException("Invalid network mask");
+                element = new InetAddressListElement(baseAddress, maskBits);
+             }
+             else
+             {
+            element = new InetAddressListElement(InetAddress.getByName(textAddr1.getText().trim()), InetAddress.getByName(textAddr2.getText().trim()));
+             }
                }
                catch(UnknownHostException e)
                {
                        MessageDialogHelper.openWarning(getShell(), Messages.get().AddAddressListElementDialog_Warning, Messages.get().AddAddressListElementDialog_EnterValidData);
                        return;
                }
+      catch(NumberFormatException e)
+      {
+         MessageDialogHelper.openWarning(getShell(), Messages.get().AddAddressListElementDialog_Warning, Messages.get().AddAddressListElementDialog_EnterValidData);
+         return;
+      }
                super.okPressed();
        }
 
-       /**
-        * @return the address1
-        */
-       public InetAddress getAddress1()
-       {
-               return address1;
-       }
-
-       /**
-        * @return the address2
-        */
-       public InetAddress getAddress2()
-       {
-               return address2;
-       }
-
-       /**
-        * @return the type
-        */
-       public int getType()
-       {
-               return type;
-       }
+   /**
+    * @return the element
+    */
+   public InetAddressListElement getElement()
+   {
+      return element;
+   }
 }
index 8075962..b65d4f8 100644 (file)
@@ -51,7 +51,7 @@ import org.eclipse.ui.forms.widgets.Section;
 import org.eclipse.ui.forms.widgets.TableWrapData;
 import org.eclipse.ui.forms.widgets.TableWrapLayout;
 import org.eclipse.ui.part.ViewPart;
-import org.netxms.client.IpAddressListElement;
+import org.netxms.client.InetAddressListElement;
 import org.netxms.client.NXCSession;
 import org.netxms.client.constants.NetworkDiscovery;
 import org.netxms.ui.eclipse.console.resources.SharedIcons;
@@ -100,13 +100,13 @@ public class NetworkDiscoveryConfigurator extends ViewPart implements ISaveableP
    @Override
    public void init(IViewSite site, IMemento memento) throws PartInitException
    {
-      super.init(site, memento);
+      super.init(site, memento);         
    }
 
    /*
     * (non-Javadoc)
     * 
-    * @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets .Composite)
+    * @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)
     */
    @Override
    public void createPartControl(Composite parent)
@@ -590,7 +590,7 @@ public class NetworkDiscoveryConfigurator extends ViewPart implements ISaveableP
    /*
     * (non-Javadoc)
     * 
-    * @see org.eclipse.ui.ISaveablePart#doSave(org.eclipse.core.runtime.IProgressMonitor )
+    * @see org.eclipse.ui.ISaveablePart#doSave(org.eclipse.core.runtime.IProgressMonitor)
     */
    @Override
    public void doSave(IProgressMonitor monitor)
@@ -685,8 +685,8 @@ public class NetworkDiscoveryConfigurator extends ViewPart implements ISaveableP
       AddAddressListElementDialog dlg = new AddAddressListElementDialog(getSite().getShell());
       if (dlg.open() == Window.OK)
       {
-         final List<IpAddressListElement> list = config.getTargets();
-         IpAddressListElement element = new IpAddressListElement(dlg.getType(), dlg.getAddress1(), dlg.getAddress2());
+         final List<InetAddressListElement> list = config.getTargets();
+         InetAddressListElement element = dlg.getElement();
          if (!list.contains(element))
          {
             list.add(element);
@@ -701,7 +701,7 @@ public class NetworkDiscoveryConfigurator extends ViewPart implements ISaveableP
     */
    private void removeTargetAddressListElements()
    {
-      final List<IpAddressListElement> list = config.getTargets();
+      final List<InetAddressListElement> list = config.getTargets();
       IStructuredSelection selection = (IStructuredSelection)activeDiscoveryAddressList.getSelection();
       if (selection.size() > 0)
       {
@@ -722,8 +722,8 @@ public class NetworkDiscoveryConfigurator extends ViewPart implements ISaveableP
       AddAddressListElementDialog dlg = new AddAddressListElementDialog(getSite().getShell());
       if (dlg.open() == Window.OK)
       {
-         final List<IpAddressListElement> list = config.getAddressFilter();
-         IpAddressListElement element = new IpAddressListElement(dlg.getType(), dlg.getAddress1(), dlg.getAddress2());
+         final List<InetAddressListElement> list = config.getAddressFilter();
+         InetAddressListElement element = dlg.getElement();
          if (!list.contains(element))
          {
             list.add(element);
@@ -738,7 +738,7 @@ public class NetworkDiscoveryConfigurator extends ViewPart implements ISaveableP
     */
    private void removeAddressFilterElements()
    {
-      final List<IpAddressListElement> list = config.getAddressFilter();
+      final List<InetAddressListElement> list = config.getAddressFilter();
       IStructuredSelection selection = (IStructuredSelection)filterAddressList.getSelection();
       if (selection.size() > 0)
       {
index 43531dd..5efd463 100644 (file)
@@ -9,7 +9,7 @@ import org.eclipse.jface.viewers.TableViewer;
 import org.eclipse.jface.viewers.Viewer;
 import org.eclipse.jface.viewers.ViewerComparator;
 import org.eclipse.swt.SWT;
-import org.netxms.client.IpAddressListElement;
+import org.netxms.client.InetAddressListElement;
 
 /**
  * Comparator for address list elements
@@ -22,13 +22,17 @@ public class AddressListElementComparator extends ViewerComparator
        @Override
        public int compare(Viewer viewer, Object e1, Object e2)
        {
-               IpAddressListElement a1 = (IpAddressListElement)e1;
-               IpAddressListElement a2 = (IpAddressListElement)e2;
+               InetAddressListElement a1 = (InetAddressListElement)e1;
+               InetAddressListElement a2 = (InetAddressListElement)e2;
                
-               int rc = compareIpAddresses(a1.getAddr1(), a2.getAddr1());
+               int rc = compareIpAddresses(a1.getBaseAddress(), a2.getBaseAddress());
                if (rc == 0)
                {
-                       rc = compareIpAddresses(a1.getAddr2(), a2.getAddr2());
+                  rc = a1.getType() - a2.getType();
+                  if (rc == 0)
+                  {
+                     rc = (a1.getType() == InetAddressListElement.SUBNET) ? a1.getMaskBits() - a2.getMaskBits() : compareIpAddresses(a1.getEndAddress(), a2.getEndAddress());
+                  }
                }
                
                int dir = ((TableViewer)viewer).getTable().getSortDirection();
@@ -46,10 +50,14 @@ public class AddressListElementComparator extends ViewerComparator
        {
                byte[] b1 = a1.getAddress();
                byte[] b2 = a2.getAddress();
+
+               int rc = b1.length - b2.length;
+               if (rc != 0)
+                  return rc;
                
                for(int i = 0; i < b1.length; i++)
                {
-                       int rc = b1[i] - b2[i];
+                       rc = ((int)b1[i] & 0xFF) - ((int)b2[i] & 0xFF);
                        if (rc != 0)
                                return Integer.signum(rc);
                }
index 01cd298..1d2a2d4 100644 (file)
@@ -6,7 +6,7 @@ package org.netxms.ui.eclipse.serverconfig.views.helpers;
 import java.io.IOException;
 import java.util.List;
 import java.util.Map;
-import org.netxms.client.IpAddressListElement;
+import org.netxms.client.InetAddressListElement;
 import org.netxms.client.NXCException;
 import org.netxms.client.NXCSession;
 import org.netxms.client.server.ServerVariable;
@@ -21,8 +21,8 @@ public class DiscoveryConfig
        private boolean useSnmpTraps;
        private int filterFlags;
        private String filter;
-       private List<IpAddressListElement> targets;
-       private List<IpAddressListElement> addressFilter;
+       private List<InetAddressListElement> targets;
+       private List<InetAddressListElement> addressFilter;
        
        /**
         * Create empty object
@@ -207,7 +207,7 @@ public class DiscoveryConfig
        /**
         * @return the targets
         */
-       public List<IpAddressListElement> getTargets()
+       public List<InetAddressListElement> getTargets()
        {
                return targets;
        }
@@ -215,7 +215,7 @@ public class DiscoveryConfig
        /**
         * @param targets the targets to set
         */
-       public void setTargets(List<IpAddressListElement> targets)
+       public void setTargets(List<InetAddressListElement> targets)
        {
                this.targets = targets;
        }
@@ -223,7 +223,7 @@ public class DiscoveryConfig
        /**
         * @return the addressFilter
         */
-       public List<IpAddressListElement> getAddressFilter()
+       public List<InetAddressListElement> getAddressFilter()
        {
                return addressFilter;
        }
@@ -231,7 +231,7 @@ public class DiscoveryConfig
        /**
         * @param addressFilter the addressFilter to set
         */
-       public void setAddressFilter(List<IpAddressListElement> addressFilter)
+       public void setAddressFilter(List<InetAddressListElement> addressFilter)
        {
                this.addressFilter = addressFilter;
        }