Merge branch 'libuv_dhcpd_dev' of http://git.komect.net/ZNJK/vcpe into libuv_dhcpd_dev

This commit is contained in:
dongwenze 2023-04-18 11:14:01 +08:00
commit efce4ce141
12 changed files with 20235 additions and 22 deletions

View File

@ -3,11 +3,13 @@ INCLUDE(CMakeDependentOption)
OPTION(VCPE_AGENT "Enable vCPE agent test application" OFF) OPTION(VCPE_AGENT "Enable vCPE agent test application" OFF)
OPTION(VCPE_PPPOE "Enable vCPE work befof PPPoE mode" OFF) OPTION(VCPE_PPPOE "Enable vCPE work befof PPPoE mode" OFF)
OPTION(DHCP_TOOLS "Enable dhcp_tools for test dhcp servers with concurrency and multi-user" OFF)
OPTION(USED_OPENDHCPD "DHCP server for vCPE" OFF) OPTION(USED_OPENDHCPD "DHCP server for vCPE" OFF)
OPTION(USED_OPENDHCPDDNS "DHCP And DNS server for vCPE" OFF) OPTION(USED_OPENDHCPDDNS "DHCP And DNS server for vCPE" OFF)
OPTION(USED_USER_VNI "Support pass user vni id from console command line" OFF) OPTION(USED_USER_VNI "Support pass user vni id from console command line" OFF)
OPTION(USED_JSON_VALIDATE "Support json protocol field validate" OFF) OPTION(USED_JSON_VALIDATE "Support json protocol field validate" OFF)
OPTION(BUILD_TESTING "Enable tests" OFF) OPTION(BUILD_TESTING "Enable tests" OFF)
# #
OPTION(USED_REDIS "Add redis database support for vCPE" OFF) OPTION(USED_REDIS "Add redis database support for vCPE" OFF)
OPTION(USED_MYSQL "Add mysql database support for vCPE" OFF) OPTION(USED_MYSQL "Add mysql database support for vCPE" OFF)
@ -157,6 +159,10 @@ ADD_SUBDIRECTORY(srcs)
ADD_SUBDIRECTORY(srcs/libs) ADD_SUBDIRECTORY(srcs/libs)
ADD_SUBDIRECTORY(srcs/service) ADD_SUBDIRECTORY(srcs/service)
IF (DHCP_TOOLS)
ADD_SUBDIRECTORY(dhcp_tools)
ENDIF ()
IF (BUILD_TESTING) IF (BUILD_TESTING)
ADD_SUBDIRECTORY(unit_test) ADD_SUBDIRECTORY(unit_test)
ENDIF () ENDIF ()

30
dhcp_tools/CMakeLists.txt Normal file
View File

@ -0,0 +1,30 @@
CMAKE_MINIMUM_REQUIRED(VERSION 3.10 FATAL_ERROR)
SET(PROJECT_TARGET dhcp_tools)
PROJECT(${PROJECT_TARGET} LANGUAGES C)
FIND_PACKAGE(PkgConfig REQUIRED)
PKG_CHECK_MODULES(GTK3 REQUIRED gtk+-3.0)
INCLUDE_DIRECTORIES(${GTK3_INCLUDE_DIRS})
LINK_DIRECTORIES(${GTK3_LIBRARY_DIRS})
INCLUDE_DIRECTORIES(. ${CMAKE_SOURCE_DIR}/srcs/include ${CMAKE_SOURCE_DIR}/srcs/libs/include)
FILE(GLOB PROJECT_HEADS ./*.h)
AUX_SOURCE_DIRECTORY(./ PROJECT_SRC)
ADD_COMPILE_OPTIONS(-Wl,—export-dynamic)
ADD_LINK_OPTIONS(-rdynamic)
ADD_DEFINITIONS(${GTK3_CFLAGS_OTHER})
ADD_EXECUTABLE(${PROJECT_TARGET} ${PROJECT_SRC} ${PROJECT_HEADS})
TARGET_LINK_LIBRARIES(${PROJECT_TARGET} common ${COMMON_LIBS} ${GTK3_LIBRARIES})
#
ADD_CUSTOM_COMMAND(TARGET ${PROJECT_TARGET}
POST_BUILD
COMMENT "!!!!!! Notice: Automatic upgreade GTK3 UI files after build project."
COMMAND ${CMAKE_COMMAND} -E make_directory "${CMAKE_CURRENT_BINARY_DIR}/res/"
COMMAND ${CMAKE_COMMAND} -E copy_if_different "${CMAKE_SOURCE_DIR}/dhcp_tools/res/style.css" "${CMAKE_CURRENT_BINARY_DIR}/res/"
COMMAND ${CMAKE_COMMAND} -E copy_if_different "${CMAKE_SOURCE_DIR}/dhcp_tools/res/main.glade" "${CMAKE_CURRENT_BINARY_DIR}/res/")

149
dhcp_tools/main_wnd.c Normal file
View File

@ -0,0 +1,149 @@
//
// Created by xajhuang on 2023/4/12.
//
#include <gtk/gtk.h>
typedef enum {
COL_VNI = 0,
COL_MAC,
COL_HOSTNAME,
COL_STEP,
COL_RESULT,
COL_STATUS,
NUM_COLS
} COL_NAME;
static GtkBuilder *g_main_builder;
static void load_css(void) {
GtkCssProvider *provider;
GdkDisplay *display;
GdkScreen *screen;
GFile *css_fp = g_file_new_for_path("./res/style.css");
GError *error = 0;
provider = gtk_css_provider_new();
display = gdk_display_get_default();
screen = gdk_display_get_default_screen(display);
gtk_style_context_add_provider_for_screen(screen,
GTK_STYLE_PROVIDER(provider),
GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
gtk_css_provider_load_from_file(provider, css_fp, &error);
}
G_MODULE_EXPORT void __mainWnd_on_destroy(GObject *object, gpointer user_data) {
gtk_main_quit();
}
static void add_item_to_list_view(GtkWidget *list,
int idx,
const char *pMac,
const char *pHostname,
const char *pDiscover,
const char *pOffer,
const char *pRequest,
const char *pAck) {
int i, j;
GtkTreeIter iter, iter_child, iter_sub;
GtkTreeStore *store = GTK_TREE_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(list)));
for (i = 0; i < 1000; i++) {
char buf[24] = {0};
char bufHost[32] = {0};
char bufVni[16] = {0};
sprintf(bufVni, "%d", i);
sprintf(bufHost, "hostname%d", i);
sprintf(buf, "06:01:02:%02X:%02X:%02X", (i & 0xFF0000) >> 16, (i & 0xFF00) >> 8, (i & 0xFF));
gtk_tree_store_append(store, &iter, NULL);
// clang-format off
gtk_tree_store_set(store, &iter,
COL_VNI, bufVni,
COL_MAC, buf,
COL_HOSTNAME, bufHost,
COL_STATUS, 20.0,
-1);
gtk_tree_store_append(store, &iter_child, &iter);
gtk_tree_store_set(store, &iter_child,
COL_VNI, "",
COL_STEP, "Discover",
COL_RESULT, "",
COL_STATUS, 10.0,
-1);
gtk_tree_store_append(store, &iter_child, &iter);
gtk_tree_store_set(store, &iter_child,
COL_VNI, "",
COL_STEP, "Offer",
COL_RESULT, "",
COL_STATUS, 10.0,
-1);
gtk_tree_store_append(store, &iter_child, &iter);
gtk_tree_store_set(store, &iter_child,
COL_VNI, "",
COL_STEP, "Request",
COL_RESULT, "",
COL_STATUS, 10.0,
-1);
gtk_tree_store_append(store, &iter_child, &iter);
gtk_tree_store_set(store, &iter_child,
COL_VNI, "",
COL_STEP, "ACK",
COL_RESULT, "",
COL_STATUS, 10.0,
-1);
// clang-format on
}
}
int main(int argc, char **argv) {
gtk_init(&argc, &argv);
load_css();
g_main_builder = gtk_builder_new();
gtk_builder_add_from_file(g_main_builder, "./res/main.glade", NULL);
GtkWidget *mainWnd = GTK_WIDGET(gtk_builder_get_object(g_main_builder, "wndMain"));
GtkWidget *macTxt = GTK_WIDGET(gtk_builder_get_object(g_main_builder, "txtMacStart"));
//gtk_style_context_add_class(gtk_widget_get_style_context(GTK_WIDGET(macTxt)), "txtMacStart");
GtkWidget *numInc = GTK_WIDGET(gtk_builder_get_object(g_main_builder, "sbReqNum"));
GtkAdjustment *adj = gtk_adjustment_new(1000, 1, 100000, 1, 0, 0);
gtk_spin_button_set_adjustment(GTK_SPIN_BUTTON(numInc), adj);
GtkWidget *numVni = GTK_WIDGET(gtk_builder_get_object(g_main_builder, "sbVni"));
GtkAdjustment *adjVni = gtk_adjustment_new(1, 1, 10000000, 1, 0, 0);
gtk_spin_button_set_adjustment(GTK_SPIN_BUTTON(numVni), adjVni);
#if 1
GtkWidget *view = GTK_WIDGET(gtk_builder_get_object(g_main_builder, "treeResult"));
GtkTreeStore *store = GTK_TREE_STORE(gtk_builder_get_object(g_main_builder, "tsDhcpInfo"));
#if 0
gtk_list_store_new(NUM_COLS,
G_TYPE_INT,
G_TYPE_STRING,
G_TYPE_STRING,
G_TYPE_STRING,
G_TYPE_STRING,
G_TYPE_STRING,
G_TYPE_STRING,
G_TYPE_FLOAT);
#endif
gtk_tree_view_set_model(GTK_TREE_VIEW(view), GTK_TREE_MODEL(store));
add_item_to_list_view(view, 0, NULL, NULL, NULL, NULL, NULL, NULL);
g_object_unref(store);
#endif
gtk_builder_connect_signals(g_main_builder, NULL);
//g_object_unref(G_OBJECT(g_main_builder));
gtk_widget_show(mainWnd);
gtk_main();
return 0;
}

469
dhcp_tools/res/main.glade Normal file
View File

@ -0,0 +1,469 @@
<?xml version="1.0"?>
<interface>
<requires lib="gtk+" version="2.16"/>
<!-- interface-naming-policy project-wide -->
<object class="GtkTreeStore" id="tsDhcpInfo">
<columns>
<!-- column-name cVni -->
<column type="gchararray"/>
<!-- column-name cMac -->
<column type="gchararray"/>
<!-- column-name cHostname -->
<column type="gchararray"/>
<!-- column-name cStep -->
<column type="gchararray"/>
<!-- column-name cResult -->
<column type="gchararray"/>
<!-- column-name cRltPrgess -->
<column type="gfloat"/>
</columns>
</object>
<object class="GtkWindow" id="wndMain">
<property name="width_request">1024</property>
<signal name="destroy" handler="__mainWnd_on_destroy"/>
<child>
<object class="GtkVBox" id="vbWnd">
<property name="visible">True</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkMenuBar" id="menuMain">
<property name="visible">True</property>
<child>
<object class="GtkMenuItem" id="menuitem1">
<property name="visible">True</property>
<property name="label" translatable="yes">_File</property>
<property name="use_underline">True</property>
<child type="submenu">
<object class="GtkMenu" id="menu1">
<property name="visible">True</property>
<child>
<object class="GtkImageMenuItem" id="imagemenuitem1">
<property name="label">gtk-new</property>
<property name="visible">True</property>
<property name="use_underline">True</property>
<property name="use_stock">True</property>
</object>
</child>
<child>
<object class="GtkImageMenuItem" id="imagemenuitem2">
<property name="label">gtk-open</property>
<property name="visible">True</property>
<property name="use_underline">True</property>
<property name="use_stock">True</property>
</object>
</child>
<child>
<object class="GtkImageMenuItem" id="imagemenuitem3">
<property name="label">gtk-save</property>
<property name="visible">True</property>
<property name="use_underline">True</property>
<property name="use_stock">True</property>
</object>
</child>
<child>
<object class="GtkImageMenuItem" id="imagemenuitem4">
<property name="label">gtk-save-as</property>
<property name="visible">True</property>
<property name="use_underline">True</property>
<property name="use_stock">True</property>
</object>
</child>
<child>
<object class="GtkSeparatorMenuItem" id="separatormenuitem1">
<property name="visible">True</property>
</object>
</child>
<child>
<object class="GtkImageMenuItem" id="imagemenuitem5">
<property name="label">gtk-quit</property>
<property name="visible">True</property>
<property name="use_underline">True</property>
<property name="use_stock">True</property>
</object>
</child>
</object>
</child>
</object>
</child>
<child>
<object class="GtkMenuItem" id="menuitem2">
<property name="visible">True</property>
<property name="label" translatable="yes">_Edit</property>
<property name="use_underline">True</property>
<child type="submenu">
<object class="GtkMenu" id="menu2">
<property name="visible">True</property>
<child>
<object class="GtkImageMenuItem" id="imagemenuitem6">
<property name="label">gtk-cut</property>
<property name="visible">True</property>
<property name="use_underline">True</property>
<property name="use_stock">True</property>
</object>
</child>
<child>
<object class="GtkImageMenuItem" id="imagemenuitem7">
<property name="label">gtk-copy</property>
<property name="visible">True</property>
<property name="use_underline">True</property>
<property name="use_stock">True</property>
</object>
</child>
<child>
<object class="GtkImageMenuItem" id="imagemenuitem8">
<property name="label">gtk-paste</property>
<property name="visible">True</property>
<property name="use_underline">True</property>
<property name="use_stock">True</property>
</object>
</child>
<child>
<object class="GtkImageMenuItem" id="imagemenuitem9">
<property name="label">gtk-delete</property>
<property name="visible">True</property>
<property name="use_underline">True</property>
<property name="use_stock">True</property>
</object>
</child>
</object>
</child>
</object>
</child>
<child>
<object class="GtkMenuItem" id="menuitem3">
<property name="visible">True</property>
<property name="label" translatable="yes">_View</property>
<property name="use_underline">True</property>
</object>
</child>
<child>
<object class="GtkMenuItem" id="menuitem4">
<property name="visible">True</property>
<property name="label" translatable="yes">_Help</property>
<property name="use_underline">True</property>
<child type="submenu">
<object class="GtkMenu" id="menu3">
<property name="visible">True</property>
<child>
<object class="GtkImageMenuItem" id="imagemenuitem10">
<property name="label">gtk-about</property>
<property name="visible">True</property>
<property name="use_underline">True</property>
<property name="use_stock">True</property>
</object>
</child>
</object>
</child>
</object>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkToolbar" id="tbMain">
<property name="visible">True</property>
<property name="toolbar_style">both</property>
<child>
<object class="GtkToolButton" id="tbStart">
<property name="visible">True</property>
<property name="label" translatable="yes">Start</property>
<property name="use_underline">True</property>
<property name="stock_id">gtk-media-play</property>
</object>
<packing>
<property name="expand">False</property>
<property name="homogeneous">True</property>
</packing>
</child>
<child>
<object class="GtkToolButton" id="tbStop">
<property name="visible">True</property>
<property name="label" translatable="yes">Stop</property>
<property name="use_underline">True</property>
<property name="stock_id">gtk-media-stop</property>
</object>
<packing>
<property name="expand">False</property>
<property name="homogeneous">True</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkVBox" id="vbSetting">
<property name="visible">True</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkFrame" id="frame1">
<property name="visible">True</property>
<property name="border_width">5</property>
<property name="label_xalign">0</property>
<child>
<object class="GtkTable" id="table1">
<property name="visible">True</property>
<property name="border_width">5</property>
<property name="n_rows">2</property>
<property name="n_columns">4</property>
<property name="column_spacing">5</property>
<property name="row_spacing">5</property>
<child>
<object class="GtkLabel" id="label2">
<property name="visible">True</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">MAC&#x8D77;&#x59CB;&#x5730;&#x5740;&#xFF1A;</property>
</object>
</child>
<child>
<object class="GtkLabel" id="label3">
<property name="visible">True</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">DHCP &#x5E76;&#x53D1;&#x8BF7;&#x6C42;&#x6570;&#xFF1A;</property>
</object>
<packing>
<property name="top_attach">1</property>
<property name="bottom_attach">2</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label4">
<property name="visible">True</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">&#x4E3B;&#x673A;&#x540D;&#x524D;&#x7F00;&#xFF1A;</property>
</object>
<packing>
<property name="left_attach">2</property>
<property name="right_attach">3</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label5">
<property name="visible">True</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">VNI &#x8D77;&#x59CB;&#x503C;&#xFF1A;</property>
</object>
<packing>
<property name="left_attach">2</property>
<property name="right_attach">3</property>
<property name="top_attach">1</property>
<property name="bottom_attach">2</property>
</packing>
</child>
<child>
<object class="GtkEntry" id="txtMacStart">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="invisible_char">&#x25CF;</property>
<property name="text" translatable="yes">06:01:02:00:00:01</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
</packing>
</child>
<child>
<object class="GtkEntry" id="entry2">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="invisible_char">&#x25CF;</property>
</object>
<packing>
<property name="left_attach">3</property>
<property name="right_attach">4</property>
</packing>
</child>
<child>
<object class="GtkSpinButton" id="sbReqNum">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="invisible_char">&#x25CF;</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="top_attach">1</property>
<property name="bottom_attach">2</property>
</packing>
</child>
<child>
<object class="GtkSpinButton" id="sbVni">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="invisible_char">&#x25CF;</property>
</object>
<packing>
<property name="left_attach">3</property>
<property name="right_attach">4</property>
<property name="top_attach">1</property>
<property name="bottom_attach">2</property>
</packing>
</child>
</object>
</child>
<child type="label">
<object class="GtkLabel" id="label1">
<property name="visible">True</property>
<property name="xpad">5</property>
<property name="label" translatable="yes">&lt;b&gt; &#x53C2;&#x6570;&#x8BBE;&#x7F6E; &lt;/b&gt;</property>
<property name="use_markup">True</property>
</object>
</child>
</object>
<packing>
<property name="position">0</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="position">2</property>
</packing>
</child>
<child>
<object class="GtkScrolledWindow" id="sclTreeView">
<property name="height_request">400</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="border_width">5</property>
<property name="hscrollbar_policy">automatic</property>
<property name="vscrollbar_policy">automatic</property>
<child>
<object class="GtkTreeView" id="treeResult">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="model">tsDhcpInfo</property>
<property name="enable_grid_lines">both</property>
<child>
<object class="GtkTreeViewColumn" id="tvcIndex">
<property name="title">VNI</property>
<property name="alignment">0.5</property>
<child>
<object class="GtkCellRendererText" id="cellrenderertext1"/>
<attributes>
<attribute name="text">0</attribute>
</attributes>
</child>
</object>
</child>
<child>
<object class="GtkTreeViewColumn" id="tvcMac">
<property name="title">MAC</property>
<property name="alignment">0.5</property>
<child>
<object class="GtkCellRendererText" id="cellrenderertext2"/>
<attributes>
<attribute name="text">1</attribute>
</attributes>
</child>
</object>
</child>
<child>
<object class="GtkTreeViewColumn" id="tvcHostname">
<property name="title">Hostname</property>
<property name="alignment">0.5</property>
<child>
<object class="GtkCellRendererText" id="cellrenderertext3"/>
<attributes>
<attribute name="text">2</attribute>
</attributes>
</child>
</object>
</child>
<child>
<object class="GtkTreeViewColumn" id="tvcStep">
<property name="sizing">autosize</property>
<property name="title">Step</property>
<property name="alignment">0.5</property>
<child>
<object class="GtkCellRendererText" id="cellrenderertext4"/>
<attributes>
<attribute name="text">3</attribute>
</attributes>
</child>
</object>
</child>
<child>
<object class="GtkTreeViewColumn" id="tvcResult">
<property name="title">Result</property>
<property name="alignment">0.5</property>
<child>
<object class="GtkCellRendererText" id="crResult"/>
<attributes>
<attribute name="text">4</attribute>
</attributes>
</child>
</object>
</child>
<child>
<object class="GtkTreeViewColumn" id="tblStatus">
<property name="title">Staus</property>
<property name="alignment">0.5</property>
<child>
<object class="GtkCellRendererProgress" id="cellrendererprogress1"/>
<attributes>
<attribute name="value">5</attribute>
</attributes>
</child>
</object>
</child>
</object>
</child>
</object>
<packing>
<property name="position">3</property>
</packing>
</child>
<child>
<object class="GtkExpander" id="epLogout">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="border_width">5</property>
<child>
<object class="GtkScrolledWindow" id="sclLogout">
<property name="height_request">150</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="hscrollbar_policy">automatic</property>
<property name="vscrollbar_policy">automatic</property>
<child>
<object class="GtkTextView" id="txtLogout">
<property name="visible">True</property>
<property name="can_focus">True</property>
</object>
</child>
</object>
</child>
<child type="label">
<object class="GtkLabel" id="label6">
<property name="visible">True</property>
<property name="label" translatable="yes">Logs</property>
</object>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">4</property>
</packing>
</child>
<child>
<object class="GtkStatusbar" id="sbMain">
<property name="visible">True</property>
<property name="spacing">2</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">5</property>
</packing>
</child>
</object>
</child>
</object>
</interface>

View File

@ -0,0 +1,484 @@
<?xml version="1.0"?>
<interface>
<requires lib="gtk+" version="2.16"/>
<!-- interface-naming-policy project-wide -->
<object class="GtkListStore" id="liststore1"/>
<object class="GtkListStore" id="liststore2"/>
<object class="GtkListStore" id="liststore3"/>
<object class="GtkListStore" id="liststore4"/>
<object class="GtkListStore" id="liststore5"/>
<object class="GtkTreeStore" id="treestore1"/>
<object class="GtkListStore" id="liststore6"/>
<object class="GtkWindow" id="wndMain">
<property name="width_request">1024</property>
<property name="height_request">800</property>
<property name="title" translatable="yes">DHCP Tools</property>
<property name="resizable">False</property>
<property name="type_hint">dialog</property>
<signal name="destroy" handler="on_window_destroy"/>
<child>
<object class="GtkVBox" id="vbWnd">
<property name="height_request">800</property>
<property name="visible">True</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkMenuBar" id="menuMain">
<property name="visible">True</property>
<child>
<object class="GtkMenuItem" id="menuFile">
<property name="visible">True</property>
<property name="label" translatable="yes">_File</property>
<property name="use_underline">True</property>
<child type="submenu">
<object class="GtkMenu" id="menu1">
<property name="visible">True</property>
<child>
<object class="GtkImageMenuItem" id="imagemenuitem1">
<property name="label">gtk-new</property>
<property name="visible">True</property>
<property name="use_underline">True</property>
<property name="use_stock">True</property>
</object>
</child>
<child>
<object class="GtkImageMenuItem" id="imagemenuitem2">
<property name="label">gtk-open</property>
<property name="visible">True</property>
<property name="use_underline">True</property>
<property name="use_stock">True</property>
</object>
</child>
<child>
<object class="GtkImageMenuItem" id="imagemenuitem3">
<property name="label">gtk-save</property>
<property name="visible">True</property>
<property name="use_underline">True</property>
<property name="use_stock">True</property>
</object>
</child>
<child>
<object class="GtkImageMenuItem" id="imagemenuitem4">
<property name="label">gtk-save-as</property>
<property name="visible">True</property>
<property name="use_underline">True</property>
<property name="use_stock">True</property>
</object>
</child>
<child>
<object class="GtkSeparatorMenuItem" id="separatormenuitem1">
<property name="visible">True</property>
</object>
</child>
<child>
<object class="GtkImageMenuItem" id="imagemenuitem5">
<property name="label">gtk-quit</property>
<property name="visible">True</property>
<property name="use_underline">True</property>
<property name="use_stock">True</property>
</object>
</child>
</object>
</child>
</object>
</child>
<child>
<object class="GtkMenuItem" id="menuitem2">
<property name="visible">True</property>
<property name="label" translatable="yes">_Edit</property>
<property name="use_underline">True</property>
<child type="submenu">
<object class="GtkMenu" id="menu2">
<property name="visible">True</property>
<child>
<object class="GtkImageMenuItem" id="imagemenuitem6">
<property name="label">gtk-cut</property>
<property name="visible">True</property>
<property name="use_underline">True</property>
<property name="use_stock">True</property>
</object>
</child>
<child>
<object class="GtkImageMenuItem" id="imagemenuitem7">
<property name="label">gtk-copy</property>
<property name="visible">True</property>
<property name="use_underline">True</property>
<property name="use_stock">True</property>
</object>
</child>
<child>
<object class="GtkImageMenuItem" id="imagemenuitem8">
<property name="label">gtk-paste</property>
<property name="visible">True</property>
<property name="use_underline">True</property>
<property name="use_stock">True</property>
</object>
</child>
<child>
<object class="GtkImageMenuItem" id="imagemenuitem9">
<property name="label">gtk-delete</property>
<property name="visible">True</property>
<property name="use_underline">True</property>
<property name="use_stock">True</property>
</object>
</child>
</object>
</child>
</object>
</child>
<child>
<object class="GtkMenuItem" id="menuitem3">
<property name="visible">True</property>
<property name="label" translatable="yes">_View</property>
<property name="use_underline">True</property>
</object>
</child>
<child>
<object class="GtkMenuItem" id="menuHelp">
<property name="visible">True</property>
<property name="label" translatable="yes">_Help</property>
<property name="use_underline">True</property>
<child type="submenu">
<object class="GtkMenu" id="menu3">
<property name="visible">True</property>
<child>
<object class="GtkImageMenuItem" id="imagemenuitem10">
<property name="label">gtk-about</property>
<property name="visible">True</property>
<property name="use_underline">True</property>
<property name="use_stock">True</property>
</object>
</child>
</object>
</child>
</object>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkToolbar" id="tbMain">
<property name="visible">True</property>
<property name="toolbar_style">both</property>
<property name="icon_size">4</property>
<property name="icon_size_set">True</property>
<child>
<object class="GtkToolButton" id="tblStart">
<property name="visible">True</property>
<property name="is_important">True</property>
<property name="label" translatable="yes">Start</property>
<property name="use_underline">True</property>
<property name="stock_id">gtk-media-play</property>
</object>
<packing>
<property name="expand">False</property>
<property name="homogeneous">True</property>
</packing>
</child>
<child>
<object class="GtkToolButton" id="Stop">
<property name="visible">True</property>
<property name="is_important">True</property>
<property name="label" translatable="yes">Stop</property>
<property name="use_underline">True</property>
<property name="stock_id">gtk-media-stop</property>
</object>
<packing>
<property name="expand">False</property>
<property name="homogeneous">True</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkVBox" id="vbContent">
<property name="visible">True</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkTable" id="table1">
<property name="visible">True</property>
<property name="n_rows">2</property>
<property name="n_columns">4</property>
<property name="column_spacing">5</property>
<property name="row_spacing">5</property>
<child>
<object class="GtkLabel" id="lblMac">
<property name="width_request">15</property>
<property name="visible">True</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">MAC&#x8D77;&#x59CB;&#x5730;&#x5740;&#xFF1A;</property>
</object>
<packing>
<property name="x_padding">5</property>
</packing>
</child>
<child>
<object class="GtkEntry" id="txtMacStart">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="invisible_char">&#x25CF;</property>
<property name="text" translatable="yes">06:01:02:00:00:01</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label1">
<property name="visible">True</property>
<property name="xalign">0</property>
<property name="ypad">2</property>
<property name="label" translatable="yes">&#x4E3B;&#x673A;&#x540D;&#x524D;&#x7F00;&#xFF1A;</property>
</object>
<packing>
<property name="left_attach">2</property>
<property name="right_attach">3</property>
<property name="x_padding">5</property>
</packing>
</child>
<child>
<object class="GtkEntry" id="entry1">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="invisible_char">&#x25CF;</property>
</object>
<packing>
<property name="left_attach">3</property>
<property name="right_attach">4</property>
<property name="x_padding">5</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="lblMac1">
<property name="visible">True</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">DHCP &#x5E76;&#x53D1;&#x8BF7;&#x6C42;&#x6570;&#xFF1A;</property>
</object>
<packing>
<property name="top_attach">1</property>
<property name="bottom_attach">2</property>
<property name="x_padding">5</property>
</packing>
</child>
<child>
<object class="GtkSpinButton" id="sbReqNum">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="max_length">5</property>
<property name="invisible_char">&#x25CF;</property>
<property name="shadow_type">none</property>
<property name="climb_rate">1</property>
<property name="snap_to_ticks">True</property>
<property name="numeric">True</property>
<property name="wrap">True</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="top_attach">1</property>
<property name="bottom_attach">2</property>
<property name="y_padding">2</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label3">
<property name="visible">True</property>
<property name="xalign">0</property>
<property name="ypad">2</property>
<property name="label" translatable="yes">VNI &#x8D77;&#x59CB;&#x503C;&#xFF1A;</property>
</object>
<packing>
<property name="left_attach">2</property>
<property name="right_attach">3</property>
<property name="top_attach">1</property>
<property name="bottom_attach">2</property>
<property name="x_padding">5</property>
</packing>
</child>
<child>
<object class="GtkSpinButton" id="sbVni">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="max_length">5</property>
<property name="invisible_char">&#x25CF;</property>
<property name="shadow_type">none</property>
<property name="climb_rate">1</property>
<property name="snap_to_ticks">True</property>
<property name="numeric">True</property>
<property name="wrap">True</property>
</object>
<packing>
<property name="left_attach">3</property>
<property name="right_attach">4</property>
<property name="top_attach">1</property>
<property name="bottom_attach">2</property>
<property name="x_padding">5</property>
<property name="y_padding">2</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkScrolledWindow" id="scrolledwindow2">
<property name="height_request">200</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="border_width">1</property>
<property name="resize_mode">immediate</property>
<property name="hscrollbar_policy">automatic</property>
<child>
<object class="GtkTreeView" id="treeResult">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="model">liststore1</property>
<property name="enable_grid_lines">both</property>
<child>
<object class="GtkTreeViewColumn" id="tvcIndex">
<property name="min_width">120</property>
<property name="title">VNI</property>
<property name="alignment">0.5</property>
<child>
<object class="GtkCellRendererText" id="crVni"/>
<attributes>
<attribute name="text">0</attribute>
</attributes>
</child>
</object>
</child>
<child>
<object class="GtkTreeViewColumn" id="tvcMac">
<property name="resizable">True</property>
<property name="min_width">120</property>
<property name="title">MAC</property>
<property name="alignment">0.5</property>
<child>
<object class="GtkCellRendererText" id="clMac"/>
<attributes>
<attribute name="text">1</attribute>
</attributes>
</child>
</object>
</child>
<child>
<object class="GtkTreeViewColumn" id="tvcDiscover">
<property name="min_width">120</property>
<property name="title">Discover</property>
<property name="alignment">0.5</property>
<child>
<object class="GtkCellRendererText" id="clDiscover"/>
<attributes>
<attribute name="text">2</attribute>
</attributes>
</child>
</object>
</child>
<child>
<object class="GtkTreeViewColumn" id="tvcOffer">
<property name="min_width">120</property>
<property name="title">Offer</property>
<property name="alignment">0.5</property>
<child>
<object class="GtkCellRendererText" id="clOffer"/>
<attributes>
<attribute name="text">3</attribute>
</attributes>
</child>
</object>
</child>
<child>
<object class="GtkTreeViewColumn" id="tvcRequest">
<property name="min_width">120</property>
<property name="title">Request</property>
<property name="alignment">0.5</property>
<child>
<object class="GtkCellRendererText" id="clRequest"/>
<attributes>
<attribute name="text">4</attribute>
</attributes>
</child>
</object>
</child>
<child>
<object class="GtkTreeViewColumn" id="tvcAck">
<property name="min_width">120</property>
<property name="title">ACK</property>
<property name="alignment">0.5</property>
<child>
<object class="GtkCellRendererText" id="crAck"/>
<attributes>
<attribute name="text">5</attribute>
</attributes>
</child>
</object>
</child>
</object>
</child>
</object>
<packing>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkScrolledWindow" id="scLogPanel">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="border_width">1</property>
<property name="hscrollbar_policy">automatic</property>
<child>
<object class="GtkTextView" id="textview1">
<property name="visible">True</property>
<property name="can_focus">True</property>
</object>
</child>
</object>
<packing>
<property name="pack_type">end</property>
<property name="position">2</property>
</packing>
</child>
</object>
<packing>
<property name="position">2</property>
</packing>
</child>
<child>
<object class="GtkStatusbar" id="statusbar1">
<property name="visible">True</property>
<property name="spacing">2</property>
<child>
<object class="GtkLabel" id="label2">
<property name="visible">True</property>
<property name="label" translatable="yes">label</property>
</object>
<packing>
<property name="position">0</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">3</property>
</packing>
</child>
</object>
</child>
</object>
<object class="GtkLabel" id="label1">
<property name="visible">True</property>
<property name="label" translatable="yes">label</property>
</object>
</interface>

19038
dhcp_tools/res/sclient.glade Normal file

File diff suppressed because it is too large Load Diff

16
dhcp_tools/res/style.css Normal file
View File

@ -0,0 +1,16 @@
label {
font: 16px "Comic Sans";
}
spinbutton {
font: 16px "Comic Sans";
}
.view {
font: 16px "Comic Sans";
}
entry {
font: 16px "Comic Sans";
}

View File

@ -4,7 +4,7 @@ IF (VCPE_AGENT)
SET(PROJECT_TARGET_AGENT vcpe_agent) SET(PROJECT_TARGET_AGENT vcpe_agent)
ENDIF () ENDIF ()
PROJECT(${PROJECT_TARGET}) PROJECT(${PROJECT_TARGET} LANGUAGES C)
ADD_DEFINITIONS(${COMMON_DEFINE}) ADD_DEFINITIONS(${COMMON_DEFINE})

View File

@ -1,6 +1,6 @@
SET(LIB_PROJECT_TARGET common) SET(LIB_PROJECT_TARGET common)
PROJECT(${LIB_PROJECT_TARGET} VERSION 1.1.0) PROJECT(${LIB_PROJECT_TARGET} LANGUAGES C VERSION 1.1.0)
STRING(REPLACE ";" ", " BUILD_CONFIG_INFO "${COMMON_DEFINE}") STRING(REPLACE ";" ", " BUILD_CONFIG_INFO "${COMMON_DEFINE}")
CONFIGURE_FILE(lib_config.h.in lib_config.h) CONFIGURE_FILE(lib_config.h.in lib_config.h)

View File

@ -11,6 +11,20 @@ extern "C" {
#define _STR(s) #s #define _STR(s) #s
#define STR(s) _STR(s) #define STR(s) _STR(s)
/**
* container_of - cast a member of a structure out to the containing structure
*
* @ptr: the pointer to the member.
* @type: the type of the container struct this is embedded in.
* @member: the name of the member within the struct.
*
*/
#define container_of(ptr, type, member) \
({ \
const typeof(((type *)0)->member) *__mptr = (ptr); \
(type *)((char *)__mptr - offsetof(type, member)); \
})
#ifndef MIN #ifndef MIN
#define MIN(a, b) \ #define MIN(a, b) \
({ \ ({ \

View File

@ -12,6 +12,7 @@
#include "zlog_module.h" #include "zlog_module.h"
#ifdef JSON_SCHEMA_ON #ifdef JSON_SCHEMA_ON
#include "json_schema/jsoncdaccord.h" #include "json_schema/jsoncdaccord.h"
#include "common.h"
#endif #endif
#define CURRENT_PROTOCOL_VERSION (1) #define CURRENT_PROTOCOL_VERSION (1)

View File

@ -219,7 +219,7 @@ static PACKET_MMAP_RING g_pkgRing;
static NIC_INFO g_nicInfo; static NIC_INFO g_nicInfo;
static uv_udp_t g_uvRawSockReq; static uv_udp_t g_uvRawSockReq;
U32 pkg_mmap_tx(U8 *pData, U32 nBytes) { void *get_pkg_memory() {
int i; int i;
ssize_t ret; ssize_t ret;
struct tpacket3_hdr *hdr; struct tpacket3_hdr *hdr;
@ -229,24 +229,28 @@ U32 pkg_mmap_tx(U8 *pData, U32 nBytes) {
g_pkgRing.index = (g_pkgRing.index + 1) % g_pkgRing.send.tp_frame_nr; g_pkgRing.index = (g_pkgRing.index + 1) % g_pkgRing.send.tp_frame_nr;
if (!(hdr->tp_status & (TP_STATUS_SEND_REQUEST | TP_STATUS_SENDING))) { if (!(hdr->tp_status & (TP_STATUS_SEND_REQUEST | TP_STATUS_SENDING))) {
U8 *p = (U8 *)hdr + TPACKET3_HDRLEN - sizeof(struct sockaddr_ll); return (U8 *)hdr + TPACKET3_HDRLEN - sizeof(struct sockaddr_ll);
memcpy(p, pData, nBytes); }
}
return NULL;
}
U32 pkg_mmap_tx(U8 *pData, U32 nBytes) {
struct tpacket3_hdr *hdr = (struct tpacket3_hdr *)(pData + sizeof(struct sockaddr_ll) - TPACKET3_HDRLEN);
hdr->tp_next_offset = 0; hdr->tp_next_offset = 0;
hdr->tp_len = nBytes; hdr->tp_len = nBytes;
hdr->tp_snaplen = nBytes; hdr->tp_snaplen = nBytes;
hdr->tp_status = TP_STATUS_SEND_REQUEST; hdr->tp_status = TP_STATUS_SEND_REQUEST;
return hdr->tp_len; return hdr->tp_len;
} }
}
return 0;
}
static int dhcp_resp_offer(PDHCP_PACKAGE pReq, PIPPOOL_INFO pIpInfo, U32 ip) { static int dhcp_resp_offer(PDHCP_PACKAGE pReq, PIPPOOL_INFO pIpInfo, U32 ip) {
U8 *pOpt;
U16 csum; U16 csum;
int tolSize; int tolSize;
PDHCP_PACKAGE pRsp = (PDHCP_PACKAGE)malloc(MAX_DHCP_PKG_SIZE); PDHCP_PACKAGE pRsp = get_pkg_memory();
U8 *pOpt = pRsp->dhcp.options;
if (pRsp == NULL) { if (pRsp == NULL) {
LOG_MOD(error, ZLOG_MOD_DHCPD, "Malloc memory error: %u\n", MAX_DHCP_PKG_SIZE); LOG_MOD(error, ZLOG_MOD_DHCPD, "Malloc memory error: %u\n", MAX_DHCP_PKG_SIZE);
@ -311,6 +315,8 @@ static int dhcp_resp_offer(PDHCP_PACKAGE pReq, PIPPOOL_INFO pIpInfo, U32 ip) {
pRsp->dhcp.giaddr = 0; pRsp->dhcp.giaddr = 0;
// DHCP Options // DHCP Options
pOpt = pRsp->dhcp.options;
// DHCP 消息类型 // DHCP 消息类型
pOpt += dhcp_add_u8_option(pOpt, OPT_MESSAGETYPE, DHCP_MSG_OFFER); pOpt += dhcp_add_u8_option(pOpt, OPT_MESSAGETYPE, DHCP_MSG_OFFER);
// 子网掩码 // 子网掩码