From patchwork Fri Mar 28 05:50:05 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Hefty, Sean" X-Patchwork-Id: 3900861 Return-Path: X-Original-To: patchwork-linux-rdma@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 2EC4A9F44E for ; Fri, 28 Mar 2014 05:50:34 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 57A7D202E6 for ; Fri, 28 Mar 2014 05:50:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 53390202F0 for ; Fri, 28 Mar 2014 05:50:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751185AbaC1Fu0 (ORCPT ); Fri, 28 Mar 2014 01:50:26 -0400 Received: from mga02.intel.com ([134.134.136.20]:2933 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751186AbaC1FuS (ORCPT ); Fri, 28 Mar 2014 01:50:18 -0400 Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga101.jf.intel.com with ESMTP; 27 Mar 2014 22:50:18 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="4.97,748,1389772800"; d="scan'208";a="501476372" Received: from cst-linux.jf.intel.com ([10.23.221.72]) by fmsmga001.fm.intel.com with ESMTP; 27 Mar 2014 22:50:17 -0700 From: sean.hefty@intel.com To: linux-rdma@vger.kernel.org Cc: Ira Weiny Subject: [PATCH 11/16] ibacm: Add thread to monitor IP address changes Date: Thu, 27 Mar 2014 22:50:05 -0700 Message-Id: <1395985810-23822-12-git-send-email-sean.hefty@intel.com> X-Mailer: git-send-email 1.7.3 In-Reply-To: <1395985810-23822-1-git-send-email-sean.hefty@intel.com> References: <1395985810-23822-1-git-send-email-sean.hefty@intel.com> Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Spam-Status: No, score=-7.3 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Ira Weiny Currently only reports events to the log Signed-off-by: Ira Weiny --- src/acm.c | 86 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 86 insertions(+), 0 deletions(-) diff --git a/src/acm.c b/src/acm.c index ebb48f4..a23e953 100644 --- a/src/acm.c +++ b/src/acm.c @@ -49,6 +49,9 @@ #include #include #include +#include +#include +#include #include "acm_mad.h" #include "acm_util.h" @@ -3368,6 +3371,86 @@ static void acm_port_down(struct acm_port *port) acm_log(1, "%s %d is down\n", port->dev->verbs->device->name, port->port_num); } + +#define NL_MSG_BUF_SIZE 4096 +static void CDECL_FUNC acm_ipnl_handler(void *context) +{ + struct sockaddr_nl addr; + int sock, len; + char buffer[NL_MSG_BUF_SIZE]; + struct nlmsghdr *nlh; + char name[IFNAMSIZ]; + char ip_str[INET6_ADDRSTRLEN]; + + if ((sock = socket(PF_NETLINK, SOCK_RAW, NETLINK_ROUTE)) == -1) { + acm_log(0, "Failed to open NETLINK_ROUTE socket"); + return; + } + + memset(&addr, 0, sizeof(addr)); + addr.nl_family = AF_NETLINK; + addr.nl_groups = RTMGRP_LINK | RTMGRP_IPV4_IFADDR; + + if (bind(sock, (struct sockaddr *)&addr, sizeof(addr)) == -1) { + acm_log(0, "Failed to bind NETLINK_ROUTE socket"); + return; + } + + while ((len = recv(sock, buffer, NL_MSG_BUF_SIZE, 0)) > 0) { + nlh = (struct nlmsghdr *)buffer; + while ((NLMSG_OK(nlh, len)) && (nlh->nlmsg_type != NLMSG_DONE)) { + struct ifaddrmsg *ifa = (struct ifaddrmsg *) NLMSG_DATA(nlh); + struct ifinfomsg *ifi = (struct ifinfomsg *) NLMSG_DATA(nlh); + struct rtattr *rth = IFA_RTA(ifa); + int rtl = IFA_PAYLOAD(nlh); + + switch (nlh->nlmsg_type) { + case RTM_NEWADDR: + { + if_indextoname(ifa->ifa_index, name); + while (rtl && RTA_OK(rth, rtl)) { + if (rth->rta_type == IFA_LOCAL) { + acm_log(0, "Address added %s : %s\n", + name, inet_ntop(ifa->ifa_family, RTA_DATA(rth), + ip_str, sizeof(ip_str))); + } + rth = RTA_NEXT(rth, rtl); + } + break; + } + case RTM_DELADDR: + { + if_indextoname(ifa->ifa_index, name); + while (rtl && RTA_OK(rth, rtl)) { + if (rth->rta_type == IFA_LOCAL) { + acm_log(0, "Address deleted %s : %s\n", + name, inet_ntop(ifa->ifa_family, RTA_DATA(rth), + ip_str, sizeof(ip_str))); + } + rth = RTA_NEXT(rth, rtl); + } + break; + } + case RTM_NEWLINK: + { + acm_log(2, "Link added : %s\n", if_indextoname(ifi->ifi_index, name)); + break; + } + case RTM_DELLINK: + { + acm_log(2, "Link removed : %s\n", if_indextoname(ifi->ifi_index, name)); + break; + } + default: + acm_log(2, "unknown netlink message\n"); + break; + } + nlh = NLMSG_NEXT(nlh, len); + } + } + return; +} + /* * There is one event handler thread per device. This is the only thread that * modifies the port state or a port endpoint list. Other threads which access @@ -3750,6 +3833,9 @@ int CDECL_FUNC main(int argc, char **argv) return -1; } + acm_log(1, "starting IP Netlink thread\n"); + beginthread(acm_ipnl_handler, NULL); + acm_activate_devices(); acm_log(1, "starting timeout/retry thread\n"); beginthread(acm_retry_handler, NULL);