]> git.ipfire.org Git - thirdparty/ipxe.git/commitdiff
[vlan] Support automatic VLAN device creation
authorMichael Brown <mcb30@ipxe.org>
Sun, 15 Jan 2023 22:35:44 +0000 (22:35 +0000)
committerMichael Brown <mcb30@ipxe.org>
Sun, 15 Jan 2023 22:35:44 +0000 (22:35 +0000)
Add the ability to automatically create a VLAN device for a specified
trunk device link-layer address and VLAN tag.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
src/include/ipxe/vlan.h
src/net/vlan.c

index 8bf79234b73a875115f803d3dbd877aae0b528f5..20bbc891dc87e4c8cf278a3d5f4edd2267768ac8 100644 (file)
@@ -80,6 +80,7 @@ extern int vlan_can_be_trunk ( struct net_device *trunk );
 extern int vlan_create ( struct net_device *trunk, unsigned int tag,
                         unsigned int priority );
 extern int vlan_destroy ( struct net_device *netdev );
+extern void vlan_auto ( const void *ll_addr, unsigned int tag );
 extern void vlan_netdev_rx ( struct net_device *netdev, unsigned int tag,
                             struct io_buffer *iobuf );
 extern void vlan_netdev_rx_err ( struct net_device *netdev, unsigned int tag,
index 81ec623f29adaebafe8aabc76a4bcc1338fdb560..d73a957110efe802128ca8fac838e3cb9d353106 100644 (file)
@@ -55,6 +55,12 @@ struct vlan_device {
        unsigned int priority;
 };
 
+/** Automatic VLAN device link-layer address */
+static uint8_t vlan_auto_ll_addr[ETH_ALEN];
+
+/** Automatic VLAN tag */
+static unsigned int vlan_auto_tag;
+
 /**
  * Open VLAN device
  *
@@ -447,6 +453,47 @@ int vlan_destroy ( struct net_device *netdev ) {
        return 0;
 }
 
+/**
+ * Configure automatic VLAN device
+ *
+ * @v ll_addr          Link-layer address
+ * @v tag              VLAN tag
+ */
+void vlan_auto ( const void *ll_addr, unsigned int tag ) {
+
+       /* Record link-layer address and VLAN tag */
+       memcpy ( vlan_auto_ll_addr, ll_addr, ETH_ALEN );
+       vlan_auto_tag = tag;
+}
+
+/**
+ * Create automatic VLAN device
+ *
+ * @v trunk            Trunk network device
+ * @ret rc             Return status code
+ */
+static int vlan_probe ( struct net_device *trunk ) {
+       int rc;
+
+       /* Do nothing unless an automatic VLAN exists */
+       if ( ! vlan_auto_tag )
+               return 0;
+
+       /* Ignore non-trunk devices */
+       if ( ! vlan_can_be_trunk ( trunk ) )
+               return 0;
+
+       /* Ignore non-matching link-layer addresses */
+       if ( memcmp ( trunk->ll_addr, vlan_auto_ll_addr, ETH_ALEN ) != 0 )
+               return 0;
+
+       /* Create automatic VLAN device */
+       if ( ( rc = vlan_create ( trunk, vlan_auto_tag, 0 ) ) != 0 )
+               return rc;
+
+       return 0;
+}
+
 /**
  * Handle trunk network device link state change
  *
@@ -503,6 +550,7 @@ static void vlan_remove ( struct net_device *trunk ) {
 /** VLAN driver */
 struct net_driver vlan_driver __net_driver = {
        .name = "VLAN",
+       .probe = vlan_probe,
        .notify = vlan_notify,
        .remove = vlan_remove,
 };